I need to find all the scripts on server which run automatically. The server crashed 2 times yesterday and I need to move all the cron scripts to move to backup server. Please tell me how to identify these scripts ?
4 Answers
I'm assuming since you mentioned cron that you're on a Linux platform, in which case you can do this,
for user in $(cut -f1 -d: /etc/passwd); do sudo crontab -u $user -l; done
This will show the cron jobs for every user on the system, so it will show you which scripts run automatically.
There will probably be some system level ones too, in which case you do this to see them,
ls /etc/cron*
-
-
@Michael Mior: At least here,
/etc/crontab
actually runs/etc/cron.FOO
.– derobertJan 19, 2011 at 17:31 -
Same here, except for the case when you need a weird schedule. Like, only run on Fridays in November. Jan 19, 2011 at 17:35
-
How can I find all teh cron jobs for all the users?? and where are these jobs stored?– vincyJan 19, 2011 at 18:36
-
1That's what the first part of my answer does, the "for user in..." command shows you all the cron jobs for all the users. They're stored in /var/spool/cron/crontabs/ usually. Jan 19, 2011 at 18:57
crontab -l
and check /etc/crontab
-
You should also check
/etc/cron.d
and/etc/cron.{daily,hourly,weekly}
if they exist. Also,/etc/anacrontab
. Jan 19, 2011 at 17:28 -
How can I find all teh cron jobs for all the users?? and where are these jobs stored?– vincyJan 19, 2011 at 18:11
crontab -l
will list all the scheduled scripts.
Hope it helps.
-
2This will only list cron jobs for the currently logged in user. Jan 19, 2011 at 17:34
-
How can I find all the cron jobs for all the users?? and where are these jobs stored?– vincyJan 19, 2011 at 18:07
/usr/etc/crontab
.