Reputation: 103
My issue.
I need to remove session files that are stored on the server in the /tmp folder older than 2 days.
I've added this in crontab in terminal.
#!/bin/bash
find /tmp/sess_* -mtime +2 -exec rm {} \;
I save it out but keep getting bad minute error, can anyone help and let me know where I am going wrong.
Thanks.
Upvotes: 0
Views: 379
Reputation: 7634
crontab
does not accept a shebang (and the shebang is wrong anyway that's obviously just a Markdown problem which has been fixed). Try, for instance,
SHELL=/bin/bash
* * * * * find /tmp/sess_* -mtime +2 -exec rm {} \;
if you want to run the job every minute. See man 5 crontab
for details.
Update:
Q: What does the * * * * *
in the minimal crontab above mean?
A: Those five fields are date and time fields controlling when the job is executed.
According to man 5 crontab
,
The time and date fields are:
field allowed values ----- -------------- minute 0-59 hour 0-23 day of month 1-31 month 1-12 (or names, see below) day of week 0-7 (0 or 7 is Sun, or use names)
So, here are some examples:
* * * * *
: every minute;00 * * * *
: the beginning of every hour;00 03 * * *
: 3 a.m. every day;00 03 01 * *
: 3 a.m. on the first day of every month;00 23 * * 0
: 11 p.m. every Sunday;00 23 * * Sun
: same as above;*/15 * * * *
: every fifteen minutes.You can get more examples and explanations by Googling things like "vixie cron tutorial".
Upvotes: 3