Type following command and press Enter.
crontab -e
This will open editor for you. Write cron command at the end of file.
Use sudo if root privileges required. e.g
sudo crontab -e
Use following pattern to create new cron job syntax:
- The number of minutes after the hour (0 to 59)
- The hour in military time (24 hour) format (0 to 23)
- The day of the month (1 to 31)
- The month (1 to 12)
- The day of the week (0 or 7 is Sun, or use name)
- The command to run
For example
0 7 * * * /path/to/your/script.sh
This syntax will run script.sh at 7:00 AM daily.
File must have executable permissions. Run following command to make file executable.
chmod +x /path/to/your/script.sh
If you want to schedule python file to run via cron, use following command instead.
0 7 * * * /usr/bin/python3 /path/to/your/pythron-file.py
Just make sure you have already installed python3.
To list existing cron jobs enter following command:
crontab -l
To remove an existing cron job enter following command:
crontab -e
Delete the line that contains your cron job and save file.