Linux Cron Jobs
Cron Jobs are ways you can automate tasks. You could set a cron job to run a scripty on a specific date or even time. Crons are a great way of doing your daily banking if you have a shop or if you wanted to run a bash script to clear out your junk mail.
When adding a cron job it’s important to get the syntax-correct. If it’s wrong your cron job might not run at the correct time. Always ensure you know the file you want to execute using a cron is from a trustworthy source. Badly written scripts sometimes bring down servers.
View Current Crons
You can view your current cron jobs by inspecting the crontab file. The easiest way is via cat
Here you will see the file with the syntax at the top with a list of cron jobs at the bottom. Your cron will look a little like this
* * * * * root /path/to/cron/file.sh > /dev/null 2>&1
The example cron job is set to run every 1 minute. This is shown via the five * at the start of the command. The cron is being run as root.
It’s worth pointing out that unless your cron requires root privileges. Then it’s always best to add cron to a normal Linux user account.
When a cron runs then a notification will be sent to the cron users default account. If you have a cron that is running every minute then this can cause a lot of mail to build up. You can use the >/dev/null 2>&1 command to stop this. Just append it to the end of your cron command like in our example above.
When you are ready to add your cron job. Use your favourite text editor like nano to edit the file and place your cron job.
How was this article?
You might also like
More from All About Linux
Open And Close Ports In FirewallD - Manage Zones In FirewallD Like IPtables, FirewallD is a Linux firewall that filters packets …