1753914 Members
8696 Online
108810 Solutions
New Discussion

Re: housekeeping script

 
Intothenewworld
Advisor

housekeeping script

I am not familiar with writing script , I would like to write a script to do the following housekeeping task

1) move the files that elder than 30 days in current directory to /tmp/30days ;
2) check the files in /tmp/30days , if any file elder than 60 days , remove it.
3) copy the files in /tmp/30days which are created on the first day of the month ( 1st of every month ) to /tmp/firstday , so that it keeps all first day files.

can advise what can i do ?

thanks.

3 REPLIES 3
Dennis Handly
Acclaimed Contributor

Re: housekeeping script

>1) move the files that older than 30 days in current directory to /tmp/30days

 

find . -type f -mtime +30 -exec mv {} /tmp/30days \;

 

>2) check the files in /tmp/30days, if any file older than 60 days, remove it.

 

find /tmp/30days -type f -mtime +60 -exec rm -f {} +

rariasn
Honored Contributor

Re: housekeeping script

Hi:

 

> 3) copy the files in /tmp/30days which are created on the first day of the month ( 1st of every month ) to /tmp/firstday , so that it keeps all first day files

 

(ll /tmp/30days |  grep -E "Jan  1|Feb  1| ..." | awk '{print $9}') | xargs -i -t mv {}  /tmp/firstday

 

rgs,

 

Dennis Handly
Acclaimed Contributor

Re: housekeeping script

>> 3) copy the files in /tmp/30days which are created on the first day of the month
>(ll /tmp/30days |  grep -E "Jan  1|Feb  1| ... ) |

 

(You don't really need those () for a subshell.)

And note these are really files modified on the first, not created.  The latter time isn't kept on HP-UX.