Welcome, Guest! Registration


Thursday, 2019-02-21
Main » 2015 » May » 2 » Save users' crontabs to files
12:22 PM
Save users' crontabs to files

Simple bash script to save all users' crontabs to files. Quite handy when need to inspect what jobs are scheduled to run on a system. The script can be helpful when you need to migrate or back up your Linux system.

It goes through the list of all users on a Linux system and saves whatever all existing crontabs to files. I have it tested on Amazon Linux AMI and on Ubuntu. It also shall work on whatever RedHat family system, like Fedora, CentOS, Simply Linux. Basically whatever supporting "crontab -l -u <user>" shall do.

Copy-paste the bash code to a file. chmod the file to be executable. Run it as root or with sudo.

while read line
  u=`echo "$line" | cut -d: -f1`
  c=`crontab -u $u -l`
  if [ $? == 0 ]; then
    echo "$c" > "$u.ct"
    echo "saved crontab for $u to $u.ct"
done < /etc/passwd
Views: 324 | Added by: ep | Tags: Linux, amazon ec2, Bash, RedHat | Rating: 0.0/0
Total comments: 0
Only registered users can add comments.
[ Registration | Login ]