Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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 ?

share|improve this question

migrated from stackoverflow.com Jan 20 '11 at 12:29

This question came from our site for professional and enthusiast programmers.

2  
Try reading /usr/etc/crontab. –  Alix Axel Jan 19 '11 at 17:26

4 Answers 4

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*
share|improve this answer
    
+1 for mentioning /etc/cron* insteadd of just /etc/crontab. –  Michael Mior Jan 19 '11 at 17:29
    
@Michael Mior: At least here, /etc/crontab actually runs /etc/cron.FOO. –  derobert Jan 19 '11 at 17:31
    
Same here, except for the case when you need a weird schedule. Like, only run on Fridays in November. –  Michael Mior Jan 19 '11 at 17:35
    
How can I find all teh cron jobs for all the users?? and where are these jobs stored? –  vincy Jan 19 '11 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 '11 at 18:57

crontab -l

and check /etc/crontab

share|improve this answer
    
You should also check /etc/cron.d and /etc/cron.{daily,hourly,weekly} if they exist. Also, /etc/anacrontab. –  Michael Mior Jan 19 '11 at 17:28
    
Thank you...it worked.. –  vincy Jan 19 '11 at 18:06
    
How can I find all teh cron jobs for all the users?? and where are these jobs stored? –  vincy Jan 19 '11 at 18:11
crontab -l

will list all the scheduled scripts.

Hope it helps.

share|improve this answer
2  
This will only list cron jobs for the currently logged in user. –  Michael Mior Jan 19 '11 at 17:34
    
How can I find all the cron jobs for all the users?? and where are these jobs stored? –  vincy Jan 19 '11 at 18:07

Take a peek into /var/spool/cron.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.