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.

4
  • 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... Commented May 25, 2016 at 10:30
  • I am only only concerned about the user scripts set as cron jobs. Commented May 25, 2016 at 10:32
  • Non-root users only? Commented May 25, 2016 at 10:34
  • Yeah, non root users only. Commented May 25, 2016 at 10:40

1 Answer 1

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.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.