Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Bash the script - Then start crying cos it wont wo
#1

I am a noob. I can do basic linux stuff but i am trying to write a script to make this easier. I have never written a script before and i am actually suprised that i have got this fat without rm'ing my entire system.

 

I have several directories that cameras upload images to all day. Basically i want this script to run as a cron job and run at midnight every night and delete all but the last 3 days worth of files.

 

I found the easeiest way to find the files was using the `find` command, so i part wrote and part found this command. If i type this in to the console it works :). It will delete all but the last 3 days worth of files.

 

find /path/to/directory/ -mtime +3 -daystart -exec rm {} \;

 

i cant celebrate too soon though. i need this command to run on 5 different directories in:

 

/path/to/directory2/

/path/to/directory3/

/path/to/directory4/

/path/to/directory5/

 

So i repeat the command 5 times and put it in to a .sh file and try and run it. :s it says

find: missing argument to `-exec' 4 times and the last line says:

rm: cannot remove `/path/to/directory4/': Is a directory

 

the script as it stands is:

 



Code:
cleanup.sh
find /path/to/directory/ -mtime +3 -daystart -exec rm {} \;
find /path/to/directory1/ -mtime +3 -daystart -exec rm {} \;
find /path/to/directory2/ -mtime +3 -daystart -exec rm {} \;
find /path/to/directory3/ -mtime +3 -daystart -exec rm {} \;
find /path/to/directory4/ -mtime +3 -daystart -exec rm {} \;




 

Please any help/advice is welcome

Thanks in advance

 

Jim

Reply


Messages In This Thread
Bash the script - Then start crying cos it wont wo - by jimpy90 - 2005-01-26, 11:47 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)