Become a Site Supporter and Never see Ads again!

Author Topic: shell script help for asterisk  (Read 4657 times)

0 Members and 1 Guest are viewing this topic.

Offline rastasean

  • in paradise
  • Trade Count: (23)
  • Needs to get out more...
  • *****
  • Posts: 3699
  • Gender: Male
shell script help for asterisk
« on: January 22, 2011, 10:39:59 AM »
So I have an asterisk <www.asterisk.org> phone system on centos 5.5 and I came across a script to purge phone recordings 1) less than 15MB in size & 2) older than 14 days but I cannot record it since it complains of various syntax errors. Below is just one of the two scripts.

The most common way of maintaining call recordings is to automate the deletion of recordings that are older than a certain time frame. The following script called OldRecordingDeletion.sh will remove all of the recordings older than 14 days.
Code: [Select]
#!/bin/bash

# Change this path to reflect your recording storage
# location
RECORDINGS=/var/spool/asterisk/monitor

# Change this number to reflect the maximum age of call
# recordings
RECORDINGEXPIRY=14

# Change this number to reflect the maximum age of the
# deletion logs
LOGEXPIRY=365

# Current date
DATE=`date`

# Delete recordings older than $EXPIRY days
find $RECORDINGS -mtime +$EXPIRY -exec rm -rfv > removal-$DATE.log

# Delete log files older than $LOGEXPRY
find . -mtime +$LOGEXPIRY -exec rm -rf

When I run it, I receive the error:
[root@localhost recordingdeletion]# ./OldRecordingDeletion.sh
./OldRecordingDeletion.sh: line 19: removal-$DATE.log: ambiguous redirect
find: missing argument to `-exec'

Would any of the developers in the house help me understand how to correct this? The path to the recordings is correct and when I open up a log file, it is completely blank.


thanks for any help
« Last Edit: January 23, 2011, 03:24:22 PM by rastasean »
Advice is a form of nostalgia, dispensing it is a way of fishing the past from the disposal, wiping it off, painting over the ugly parts and recycling it for more than it’s worth.

Offline if_then_else

  • Trade Count: (0)
  • Taperssection Member
  • ***
  • Posts: 433
Re: perl script help for asterisk
« Reply #1 on: January 22, 2011, 08:27:56 PM »
find $RECORDINGS -mtime +$EXPIRY -exec rm -rfv > removal-$DATE.log

Spaces in the file name due to the date format?

Just use quotes, e.g.:


Code: [Select]
find $RECORDINGS -mtime +$EXPIRY -exec rm -rfv > "removal-${DATE}.log"

Offline rastasean

  • in paradise
  • Trade Count: (23)
  • Needs to get out more...
  • *****
  • Posts: 3699
  • Gender: Male
Re: perl script help for asterisk
« Reply #2 on: January 22, 2011, 10:14:04 PM »
Thanks for the help but unfortunately there's a new error. I'll show that in a min.

This is how a recording is saved in the /monitor directory: q2603-20110121-191839-1295659112.72.wav and another style: OUT2600-20110117-003458-1295246098.9.wav

This script does not look complicated at all but it just seems like I'm almost there to get it working.

new error:

[root@asterisx recordingdeletion]# ./OldRecordingDeletion.sh
find: missing argument to `-exec'
find: missing argument to `-exec'



find $RECORDINGS -mtime +$EXPIRY -exec rm -rfv > removal-$DATE.log

Spaces in the file name due to the date format?

Just use quotes, e.g.:


Code: [Select]
find $RECORDINGS -mtime +$EXPIRY -exec rm -rfv > "removal-${DATE}.log"
Advice is a form of nostalgia, dispensing it is a way of fishing the past from the disposal, wiping it off, painting over the ugly parts and recycling it for more than it’s worth.

Offline if_then_else

  • Trade Count: (0)
  • Taperssection Member
  • ***
  • Posts: 433
Re: perl script help for asterisk
« Reply #3 on: January 23, 2011, 05:01:30 AM »
new error:

[root@asterisx recordingdeletion]# ./OldRecordingDeletion.sh
find: missing argument to `-exec'
find: missing argument to `-exec'


How about this?

Code: [Select]
for i in `find $RECORDINGS -type f -name "*.wav" -mtime +$EXPIRY`; do rm -rfv $i; done >> "removal-${DATE}.log"
« Last Edit: January 23, 2011, 05:04:03 AM by if_then_else »

Offline live2496

  • Trade Count: (6)
  • Taperssection Member
  • ***
  • Posts: 701
  • Gender: Male
    • Gidluck Mastering
Re: perl script help for asterisk
« Reply #4 on: January 23, 2011, 10:47:58 AM »
Is $EXPIRY defined? When I run it I get a blank line if I put "echo $EXPIRY" in the script.
AEA R88MKII > SPL Crimson 3 > Tascam DA-3000

Offline thekhz

  • Trade Count: (0)
  • Taperssection Newbie
  • *
  • Posts: 18
Re: perl script help for asterisk
« Reply #5 on: January 23, 2011, 03:01:06 PM »
It is a shell script, not a perl script. Just saying.  If it was a perl script, it would be #!/bin/perl .

I made changes to the script to get it to run, but since running the script on your system deletes files, I am not responsible for any files that are deleted in error.

The changes that I made are highligted in bold.

#!/bin/bash
# path to reflect your recording storage
# location
RECORDINGS=/var/spool/asterisk/monitor

# Change this number to reflect the maximum age of call
# recordings
RECORDINGEXPIRY=14

# Change this number to reflect the maximum age of the
# deletion logs
LOGEXPIRY=365

# Current date
# I didn't like the date format with spaces.
DATE=`date "+%Y-%m-%d_%H:%M:%S"`

# Delete recordings older than $EXPIRY days
find $RECORDINGS -mtime +$RECORDINGEXPIRY -exec rm -rfv {} \; > removal-$DATE.log

# Delete log files older than $LOGEXPRY
find . -mtime +$LOGEXPIRY -exec rm -rf {} \;
« Last Edit: January 23, 2011, 03:04:00 PM by thekhz »

Offline rastasean

  • in paradise
  • Trade Count: (23)
  • Needs to get out more...
  • *****
  • Posts: 3699
  • Gender: Male
Re: shell script help for asterisk
« Reply #6 on: January 23, 2011, 03:29:31 PM »
^^ thanks for the help. Looks like that will actually work. Right now I don't have any recordings that old but at least its not giving an error.

I updated the subject since this is a shell script.
Advice is a form of nostalgia, dispensing it is a way of fishing the past from the disposal, wiping it off, painting over the ugly parts and recycling it for more than it’s worth.

Offline taperj

  • Trade Count: (5)
  • Taperssection Member
  • ***
  • Posts: 917
  • Gender: Male
Re: shell script help for asterisk
« Reply #7 on: January 23, 2011, 09:47:42 PM »
This is admittedly nitpicky but...  I don't like seeing excessive force in commands, precision is always key. Don't use a hacksaw when you need a scalpel, right?

I, personally would change

Code: [Select]
find $RECORDINGS -mtime +$RECORDINGEXPIRY -exec rm -rfv {} \; > removal-$DATE.log
to
Code: [Select]
find $RECORDINGS -mtime +$RECORDINGEXPIRY -exec rm -fv {} \; > removal-$DATE.log

and

Code: [Select]
find . -mtime +$LOGEXPIRY -exec rm -rf {} \;

to
Code: [Select]
find . -mtime +$LOGEXPIRY -exec rm -f {} \;

There is never a reason to use the -r (recursive) removal unless you are deleting directories. If this script was coded at all improperly, using -r in combination with -f (force) could cause catastrophic damage. Whereas just -f would only remove files and refuse to delete directories.

Enjoy,
J

« Last Edit: January 23, 2011, 09:55:06 PM by taperj »
Rig: Neumann skm184 or Neumann skm140 > Sound Devices Mixpre > Olympus LS-10 or Korg MR-1

Just ask the axis, he knows everything.

 

RSS | Mobile
Page created in 0.055 seconds with 31 queries.
© 2002-2024 Taperssection.com
Powered by SMF