Script that erases recordings after 5 years

Discussion in 'General' started by visiontrading, Apr 23, 2010.

  1. visiontrading

    Joined:
    Apr 12, 2010
    Messages:
    12
    Likes Received:
    0
    To all experts here,

    I know my hard drive will eventually get filled up by recorded calls and become unresponsive. This will happen sooner rather later especially when I have set to record all inbound and outbound calls to "always". I wonder if there's a script or a cron job that automatically erases recorded calls and starts fresh every now and then say 5 years.

    Any help will be appreciated.
     
  2. dicko

    Joined:
    Oct 24, 2008
    Messages:
    4,099
    Likes Received:
    0
    yes

    man find

    (pay attention to mtime and --delete)
     
  3. visiontrading

    Joined:
    Apr 12, 2010
    Messages:
    12
    Likes Received:
    0
    Hi dicko,

    Could you please elaborate on that?
     
  4. dicko

    Joined:
    Oct 24, 2008
    Messages:
    4,099
    Likes Received:
    0
    Sure

    man find

    means RTFM (this time for the command find)

    find /var/spool/asterisk/monitor/ -mtime +365 -delete

    will delete all the files it finds in that directory that haven't been modified for at least a year (at least three quarters of the time it will)
     
  5. visiontrading

    Joined:
    Apr 12, 2010
    Messages:
    12
    Likes Received:
    0
    Is 365 days the maximum? I think my hard drive can handle up to 5 years worth of recordings? Can this be done? In your example, the parameter "-delete". How is different from "xargs rm" and "-exec rm {} \"?

    I found these scripts elsewhere.

    find /var/spool/asterisk/monitor -type f -mtime +365 | xargs rm

    0 3 * * * find /var/spool/asterisk/monitor -mtime +365 -exec rm {} \;

    find /var/spool/asterisk/monitor -mtime +365 -exec rm -v {} \;

    0 2 * * * find /var/spool/asterisk/monitor -mtime +365 -exec rm -f {} \;

    How are these parameters different from your example??

    Specifically, what I am looking to get done is to have a script that automatically checks see if there's anything in /var/spool/asterisk/monitor/ that is older than 5 years every week on Sunday at a certain time.

    I really appreciate your help, dicko! Sorry for being such a newbie in Linux.
     
  6. dicko

    Joined:
    Oct 24, 2008
    Messages:
    4,099
    Likes Received:
    0
    The limit is not 365 that was an example figure out 5 x 365 + 1 and use that for a close approximation of five years. Again

    man find

    will clarify for you.

    some versions of find don't have the -delete option, yours does, those other commands in effect do exactly the same. it is always good practice to use absolute paths in cron jobs as cron runs with a limited environment, so replace find with /usr/bin/find.


    as to the cron jobs, that is also a RTFM, your examples run at 3am or 2am everyday

    man cron

    and of course "google is your friend"
     
  7. johnme

    Joined:
    Nov 28, 2008
    Messages:
    148
    Likes Received:
    0
    Hi

    create a file in /etc/cron.daily/ with name 'monitor_cleanup' and put in it the folowing text.


    #!/bin/sh
    /usr/bin/find /var/spool/asterisk/monitor/ -maxdepth 1 -type f -mtime +30 | /usr/bin/xargs /bin/rm -f >/dev/null 2>&1


    +30 meen for 30 days. So put +1826 (as dicko says) for 5 years.
    This is mine script and it works fine.

    Bye
    John
     

Share This Page