Skip to content

Instantly share code, notes, and snippets.

@henri
Created August 5, 2025 02:29
Show Gist options
  • Save henri/b918454ff7ec91e31d9fd9aac8e446e3 to your computer and use it in GitHub Desktop.
Save henri/b918454ff7ec91e31d9fd9aac8e446e3 to your computer and use it in GitHub Desktop.
crontab cheat sheet
#!/bin/bash
#
# (C)2020 Henri Shustak
# Released Under the MIT Licence
# https://mit-license.org/
#
# dump the crontab
user_name=$(whoami)
host_name=$(hostname)
day=$(date +%w)
# test that varable HOME is in your path if you run this via crontab
cron_dump_dir="$HOME/backup-config/crontab"
# create the directory if it is not present
if ! [ -d $cron_dump_dir ] ; then mkdir -p $cron_dump_dir ; fi
# dump that crontab
cron_dump_file="${cron_dump_dir}/${host_name}-${user_name}-crontab-$day"
if [ -d "${cron_dump_dir}" ] ; then
crontab -l > "${cron_dump_file}"
else
echo "cron_dump_dir not avaialble : ${cron_dump_dir}"
exit -99
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment