LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 12-17-2009, 07:10 PM   #1
chuckycharms
LQ Newbie
 
Registered: Nov 2009
Posts: 11

Rep: Reputation: 0
Count files in dir then move that many files in a script?


Hello World,

K, this is what I got - from a crontab run a script (understand that part), this script needs to count the amount of files in /outgoing/, then take 30 less that number, and move that many files from /readycalls/.

I need to keep the asterisk outgoing que full of .call files with out having to many in there at any given time.

Any help would be awesome!!
 
Old 12-17-2009, 08:09 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,978
Blog Entries: 11

Rep: Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879
I don't know anything about astrisk and its inner workings,
but to me moving 30 random files from a spool sounds like
trouble in the making. Can you be more specific with your
requirements?


Cheers,
Tink
 
Old 12-18-2009, 08:57 AM   #3
Doc Kaos
LQ Newbie
 
Registered: May 2009
Posts: 3

Rep: Reputation: 0
In bash I use
Code:
#!/bin/bash
TOTAL_CALLS_CMD=$(find /outgoing/ -mindepth 1 -maxdepth 1 -type f | wc -l)
declare -i REDUCED=$TOTAL_CALLS_CMD-30

echo Total: $TOTAL_CALLS_CMD
echo Reduced: $REDUCED
Then you could use a while loop for while TOTAL_CALLS_CMD -gt $REDUCED move a file or however you need to do that.

You should also of course make sure there is more than 30 to begin with, etc.

Last edited by Doc Kaos; 12-18-2009 at 08:59 AM. Reason: Missed slash in code
 
Old 12-18-2009, 11:31 AM   #4
chuckycharms
LQ Newbie
 
Registered: Nov 2009
Posts: 11

Original Poster
Rep: Reputation: 0
Thanks for the code! I will see if I can make that work.

In regards to how and why, its actually a very simple procedure. Asterisk has a directory /var/spool/asterisk/outgoing/ , when you drop a properly formated .call file into the dir, it follows the specified .call file and makes an outbound call. Its how you initiate outbound calling in asterisk.

That being said, I am building an alert system for the public school district I administer, this system is managed via a web based 'wizard' that I have made. It also send sms txts, and emails to registered users. When the alert is configured, it drops all of the appropriate .call files into a temp directory, a coulple thousand. Then a cron job moves those files into the outgoing directory every 1 min. However, if there are more calls trying to get made than the amount of channels (phone lines) available, it will just skip the call. So, If i dropped in 2000 call files, with only 40 channels available, it would only make 40 calls. So, I need just need to drop in no more than 30-40 at a time. Hence the requested bash script.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating a script to move or copy files into multiple directories below the files matthes138 Linux - Newbie 5 08-25-2009 04:57 PM
PERL count files in a dir Asteroid Programming 12 07-09-2009 12:59 PM
Count # of dir or # of files melissatoday Linux - Newbie 1 06-03-2006 11:03 AM
find and move most recent files in dir backnine_99 Linux - Software 2 06-14-2005 12:03 PM
rename script all files in dir Longinus Linux - Newbie 8 08-02-2004 12:24 AM


All times are GMT -5. The time now is 08:04 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration