linux crontab - ghdrako/doc_snipets GitHub Wiki


tags:

  • automation
  • linux
  • sysadmin

Linux crontab

Syntax

MIN HOUR DOM MON DOW CMD

Check Cron Daemon Status

sudo systemctl status cron
sudo systemctl status crond

Simulate cron’s environment by clearing your environment variables

env -i /bin/bash --noprofile --norc -c "/path/to/your_script.sh"

Redirect Output and Errors

*/10 * * * * /path/to/your_script.sh >> /path/to/log_$(date +'\%Y-\%m-\%d').log 2>&1  # nie dziala 
*/10 * * * * /path/to/your_script.sh >> /path/to/log_$(date -I).log 2>&1 # dziala

Check the Cron Logs

/var/log/cron  # redhat
tail -f /var/log/cron

List not commented crontab jobs

crontab -l | grep -v -E '^[:space:](/ghdrako/doc_snipets/wiki/:space:)*#'
crontab -l | sed '/^[:space:](/ghdrako/doc_snipets/wiki/:space:)*#/d'