NETGEAR is aware of a growing number of phone and online scams. To learn how to stay safe click here.

Forum Discussion

beatwiho's avatar
beatwiho
Aspirant
Aug 09, 2015

cron job with shell script

Hi,

 

the pictures of my network cameras are uploaded via ftp to the NAS.

I need a cron job that deletes files older than 7 days automatically.

i enabled root SSH access to the NAS already.

i do not know how the script is created and where it needs to be upload and what the script must contains.

and i dont know how to create the cron job.

I would be very grateful for any help.

2 Replies

Replies have been turned off for this discussion
  • Danthem's avatar
    Danthem
    NETGEAR Employee

    Hi beatwiho,

     

    First of all please note that incorrect SSH usage may result in rejected support (until you factory default).. The script below is not official and is used at your own risk.

     

    Anyways, I don't know what NAS you have as you didn't write it but assuming that you have a OS6 unit and running the default volume name, the script could look like this:

     

    find /data/SHARE/SUBFOLDER/* -mtime +7 -exec rm {} \; 

     

    You will need to change "SHARE/SUBFOLDER" to whatever the path is to your folder.. For instance if it's in cameras/videos the path should be /data/cameras/videos/*. Note that "data" is the default name of OS6 volume.

     Note that this is for OS6, OS4 would be different.

     

    You can then create a cronjob to run, let's say at 01:00 every day, week, month and year, edit your crontab by running 

     

    crontab -e

     

    and then, using whatever text editor pops up (vi most likely) modify your crontab file to have the following entry at the bottom:

     

    0 1 * * * find /data/SHARE/SUBFOLDER/* -mtime +7 -exec rm {} \;

    At 0 minutes of the hour, 1st hour of the day, every day of the month, every month of the year, every weekday (mon-sun)  (so; 01:00 every day), run the script that finds every file older than 7 days in folder X and then RM it. Note that this script does not delete subfolders, only files.

     

    I'm writing this from memory and with no possibility to test it at the moment, I'd recommend setting it up on a test folder first to make sure it works as intended. There may be other ways to do this, but this is a fairly simple way.

     

    and once again; the above and any SSH usage is completely at your own risk.

     

     

     

    • beatwiho's avatar
      beatwiho
      Aspirant

      Hi Danthem,

      Thanks for the detailed description.
      running like a charm.

NETGEAR Academy

Boost your skills with the Netgear Academy - Get trained, certified and stay ahead with the latest Netgear technology! 

Join Us!

ProSupport for Business

Comprehensive support plans for maximum network uptime and business peace of mind.

 

Learn More