|
Subject
|
crontab to clear tmp files
|
| | Posted by | skb104 (DH New User
) | | Posted on | 06/18/06 09:34 AM |
|
|
I am trying to write a crontab that will clear all of my non-session files out of the /tmp directory every hour: Here is the contents of my crontab file: 17 * * * * /home/<username>/hourly/clear_tmp.sh
Inside of clear_tm.sh I have: #!/bin/bash rm -f $(find /tmp -type f | grep -v sess_);
Im a little bit of a newbie with the crontabs, can someone let me know where my problem is? Thanks in advance.
|
|
|
|
Subject
|
Re: crontab to clear tmp files
[re: skb104]
|
| | Posted by | norm1037 (DH Smarty Pants) | | Posted on | 06/18/06 11:31 AM |
|
|
Is your .sh script file executable with a chmod of 755?
What error message do you get?
-- Norm Opinions are my own views and not the views of DreamHost. Any advice offered by me should be acted upon at your own risk.
|
|
|
|
Subject
|
Re: crontab to clear tmp files
[re: norm1037]
|
| | Posted by | skb104 (DH New User
) | | Posted on | 06/18/06 11:42 AM |
|
|
Yes, it is set to 755. I am actually not getting an error message, but I am still seeing files in the tmp directory that are several hours old, indicating that the script isnt working properly.
|
|
|
|
Subject
|
Re: crontab to clear tmp files
[re: skb104]
|
| | Posted by | norm1037 (DH Smarty Pants) | | Posted on | 06/18/06 11:49 AM |
|
|
Are you putting /tmp as in the system tmp or your own user /tmp as in say /home/username/tmp? The crontab will be looking in the system /tmp folder unless you give the full path.
Later. Is that just a typo btw in your OP where you left the 'p' off tmp?
-- Norm Opinions are my own views and not the views of DreamHost. Any advice offered by me should be acted upon at your own risk.
Edited by norm1037 on 06/18/06 11:59 AM (server time).
|
|
|
|
Subject
|
Re: crontab to clear tmp files
[re: skb104]
|
| | Posted by | sdayman (DH Enthusiast) | | Posted on | 06/18/06 01:29 PM |
|
|
Have you run this script manually with any success?
-Scott
|
|
|
|
Subject
|
Re: crontab to clear tmp files
[re: sdayman]
|
| | Posted by | skb104 (DH New User
) | | Posted on | 06/18/06 07:47 PM |
|
|
Its odd, it seems as though its not working now, but it had been earlier in the week (or at least I wasnt seeing any tmp files doing the same activity that usually creates them). Does anybody whose a better shell scripter than myself see a problem with the script?
|
|
|
|
Subject
|
Re: crontab to clear tmp files
[re: skb104]
|
| | Posted by | sdayman (DH Enthusiast) | | Posted on | 06/18/06 08:24 PM |
|
|
I use xargs for operations like this. I use -user so I ignore everybody else's files. I also use full paths since cron doesn't set all your paths. This is how I'd do it:
#!/bin/bash /usr/bin/find /tmp -user USERNAME -type f | /bin/grep -v sess_ | /usr/bin/xargs /bin/rm -f
-Scott
|
|
|
|
Subject
|
Re: crontab to clear tmp files
[re: sdayman]
|
| | Posted by | skb104 (DH New User
) | | Posted on | 06/19/06 06:23 PM |
|
|
Thanks Scott, I used that and it works perfectly now, thanks so much for your help.
|
|
|