1

I am looking for some script or terminal command to list all the scripts (preferably with their paths) which are run on a periodic basis by cron, cron.daily. I am not looking for any filter for time-period of the script and want all the scripts listed ( however some administrators may want this kind of filter).

Purpose: To document all scripts running periodically so that debugging or fault check , updating and transferring to a newer system is easy and efficient.

  • Simplistically you're asking what jobs are in cron; narrowed down to just scripts, not binaries? What about scripts that are subsequently called by those top-level scripts? That would be a bit more involved... – Jeff Schaller May 25 '16 at 10:30
  • I am only only concerned about the user scripts set as cron jobs. – ankit7540 May 25 '16 at 10:32
  • Non-root users only? – Jeff Schaller May 25 '16 at 10:34
  • Yeah, non root users only. – ankit7540 May 25 '16 at 10:40
2

To find the filenames and script types of all scripts run from cron by non-root users (does not identify user):

find /var/spool/cron/crontabs/ -type f ! -name 'root' \
  -exec awk '!/^[[:blank:]]*(#|$)/ {print $6}' {} + | 
    xargs -d'\n' file | grep -i script
/home/cas/scripts/fetch.sh:               Bourne-Again shell script, ASCII text executable
/usr/local/sbin/backup-postgres.sh:       Bourne-Again shell script, ASCII text executable

To find all executables (binaries & scripts) run from cron by non-root users (identifies user):

find /var/spool/cron/crontabs/ -type f ! -name 'root' \
  -execdir awk '!/^[[:blank:]]*(#|$)/ {print FILENAME"\t"$6}' {} + |
  sed -e 's:^./::'
cas   /home/cas/scripts/fetch.sh
postgres      /usr/local/sbin/backup-postgres.sh

Of course, both of these have to be run as root. Only root can read the crontabs of all users.

Note: The crontabs may be in a different directory on your system. Check the documentation for your cron daemon.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.