create crontab code example
Example 1: add new cron job in linux
For editing the cron job file :
crontab -e
For listing all the running cron job
systemctl status cron ----OR---- crontab -l
Example 2: how to edit crontab in linux
Step 1 : crontab -e
Step 2 : Select your prefered editor for the file.
Steo 3 : Add the command that you want to execute from cron and save that file.
Example : 1 0 * * 0 rm /home/jones/*.log > /dev/null 2>&1
Step 4 : check if cron is activate using command
crontab -l
Example 3: syntax crontab
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user command to be executed
example :
# 50 12 * * * ----- run every day at 12.50
# */5 * * * * ----- run every 5 minutes