1

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 ?

1
  • 2
    Try reading /usr/etc/crontab.
    – Alix Axel
    Jan 19, 2011 at 17:26

4 Answers 4

6

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*
5
  • +1 for mentioning /etc/cron* insteadd of just /etc/crontab. Jan 19, 2011 at 17:29
  • @Michael Mior: At least here, /etc/crontab actually runs /etc/cron.FOO.
    – derobert
    Jan 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?
    – vincy
    Jan 19, 2011 at 18:36
  • 1
    That'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.
    – Rich Adams
    Jan 19, 2011 at 18:57
3

crontab -l

and check /etc/crontab

2
  • 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?
    – vincy
    Jan 19, 2011 at 18:11
2

crontab -l

will list all the scheduled scripts.

Hope it helps.

2
  • 2
    This 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?
    – vincy
    Jan 19, 2011 at 18:07
1

Take a peek into /var/spool/cron.

You must log in to answer this question.