Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 12-17-2009, 07:10 PM   #1
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
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
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

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

Rep: Reputation: 0
In bash I use
TOTAL_CALLS_CMD=$(find /outgoing/ -mindepth 1 -maxdepth 1 -type f | wc -l)

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
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.


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 > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:40 PM.

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