{"id":1996,"date":"2023-01-15T16:27:07","date_gmt":"2023-01-15T16:27:07","guid":{"rendered":"https:\/\/cult.technology\/?p=1996"},"modified":"2023-01-31T05:07:55","modified_gmt":"2023-01-31T05:07:55","slug":"how-to-set-up-cron-jobs-in-linux","status":"publish","type":"post","link":"https:\/\/cult.technology\/how-to-set-up-cron-jobs-in-linux\/","title":{"rendered":"How to Set up Cron Job in Linux? [Do’s and Dont’s]"},"content":{"rendered":"
Doing repetitive tasks is tedious and boring. It is the feeling that we all have experienced but but it doesn’t have to be that way. One such popular way of automatic scheduling repetitive tasks, is using Cron jobs. This article is all about set up cron job in linux and scheduling the cron jobs to run the scripts automatically.<\/p>\n
You may have this task, like –<\/p>\n
All these things are not exciting if we do it manually each and every day. Writing a small script and executing it everyday is quite possible with cron jobs.<\/p>\n
Cron is a powerful feature of unix-based operating system to automate and schedule tthe repetitive tasks. With a little bit of configuration, you can get a cron job up and running automating your manual tasks that helps you frees up frrom this work so that we all can focus on the more important things.<\/p>\n
We can define N number of cron jobs and they are all defined in a crontab files and controlled by cron daemon.<\/p>\n
Before we proceed on how do we set up a cron job in linux, let’s understand the syntax of cron job.<\/p>\n
Crontab syntax typically consists of five important parts. As depicted in this picture below, we need to specify the time, date or week you need the cron job to be scheduled. All these five parts are separated by spaces.<\/p>\n
<\/p>\n
And finally, we can define the script to run at these time intervals.<\/p>\n
Here is the example script that takes the backup of the database at 12:30 PM on the first day of every month –<\/p>\n
Now we know how does a cron syntax looks like, let’s go ahead and set-up a cron job in linux. Here is the step-wise guide –<\/p>\n Here we are taking the output to trending_apps_scrapper.log file. You can view the log file to verify if the script is running properly as intended to run.<\/span><\/p>\n Once the cron job is saved, daemon reads the file and executes the tasks as defined in the specified intervals. It also continuously monitors if there are any changes to the cron job in the background.<\/p>\n Once you have set up the cron job, you can verify it by running the command below in the terminal –<\/p>\n This should list down all the cron jobs you have configured.<\/p>\n <\/p>\n Note that this will only list down the jobs. You cannot edit the job from here. You need to use the crontab -e command again to modify the job.<\/p>\n So that’s all from our end. You can follow the same steps to schedule a cron job in any of the linux distributions like Ubuntu, Kbuntu etc.<\/p>\n Say good bye to repetitive tasks with scheduling and cron jobs!!<\/p>\n","protected":false},"excerpt":{"rendered":" Doing repetitive tasks is tedious and boring. It is the feeling that we all have experienced but but it doesn’t have to be that way. One such popular way of automatic scheduling repetitive tasks, is using Cron jobs. This article is all about set up cron job in linux and scheduling the cron jobs to […]<\/p>\n","protected":false},"author":1,"featured_media":2002,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,5],"tags":[340,93,342,341],"blocksy_meta":{"styles_descriptor":{"styles":{"desktop":"","tablet":"","mobile":""},"google_fonts":[],"version":5}},"featured_image_urls":{"full":["https:\/\/cult.technology\/wp-content\/uploads\/2023\/01\/set-up-cron-job-in-linux.jpg",1920,1080,false],"thumbnail":["https:\/\/cult.technology\/wp-content\/uploads\/2023\/01\/set-up-cron-job-in-linux-150x150.jpg",150,150,true],"medium":["https:\/\/cult.technology\/wp-content\/uploads\/2023\/01\/set-up-cron-job-in-linux-300x169.jpg",300,169,true],"medium_large":["https:\/\/cult.technology\/wp-content\/uploads\/2023\/01\/set-up-cron-job-in-linux-768x432.jpg",768,432,true],"large":["https:\/\/cult.technology\/wp-content\/uploads\/2023\/01\/set-up-cron-job-in-linux-1024x576.jpg",1024,576,true],"1536x1536":["https:\/\/cult.technology\/wp-content\/uploads\/2023\/01\/set-up-cron-job-in-linux-1536x864.jpg",1536,864,true],"2048x2048":["https:\/\/cult.technology\/wp-content\/uploads\/2023\/01\/set-up-cron-job-in-linux.jpg",1920,1080,false],"wpzoom-rcb-block-header":["https:\/\/cult.technology\/wp-content\/uploads\/2023\/01\/set-up-cron-job-in-linux.jpg",800,450,false],"wpzoom-rcb-block-header-square":["https:\/\/cult.technology\/wp-content\/uploads\/2023\/01\/set-up-cron-job-in-linux.jpg",530,298,false],"wpzoom-rcb-block-step-image":["https:\/\/cult.technology\/wp-content\/uploads\/2023\/01\/set-up-cron-job-in-linux.jpg",750,422,false],"wpzoom-rcb-structured-data-1_1":["https:\/\/cult.technology\/wp-content\/uploads\/2023\/01\/set-up-cron-job-in-linux.jpg",500,281,false],"wpzoom-rcb-structured-data-4_3":["https:\/\/cult.technology\/wp-content\/uploads\/2023\/01\/set-up-cron-job-in-linux.jpg",500,281,false],"wpzoom-rcb-structured-data-16_9":["https:\/\/cult.technology\/wp-content\/uploads\/2023\/01\/set-up-cron-job-in-linux.jpg",480,270,false]},"post_excerpt_stackable":" Doing repetitive tasks is tedious and boring. It is the feeling that we all have experienced but but it doesn’t have to be that way. One such popular way of automatic scheduling repetitive tasks, is using Cron jobs. This article is all about set up cron job in linux and scheduling the cron jobs to run the scripts automatically. You may have this task, like – taking the database backup everyday, or sending a reminder emails to customers at a specific time of the day, or clean up the log files or junk files at the end of the day.…<\/p>\n","category_list":"How To<\/a>, Linux<\/a>","author_info":{"name":"cult.technology","url":"https:\/\/cult.technology\/author\/cult-technology\/"},"comments_num":"0 comments","_links":{"self":[{"href":"https:\/\/cult.technology\/wp-json\/wp\/v2\/posts\/1996"}],"collection":[{"href":"https:\/\/cult.technology\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cult.technology\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cult.technology\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cult.technology\/wp-json\/wp\/v2\/comments?post=1996"}],"version-history":[{"count":10,"href":"https:\/\/cult.technology\/wp-json\/wp\/v2\/posts\/1996\/revisions"}],"predecessor-version":[{"id":2010,"href":"https:\/\/cult.technology\/wp-json\/wp\/v2\/posts\/1996\/revisions\/2010"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cult.technology\/wp-json\/wp\/v2\/media\/2002"}],"wp:attachment":[{"href":"https:\/\/cult.technology\/wp-json\/wp\/v2\/media?parent=1996"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cult.technology\/wp-json\/wp\/v2\/categories?post=1996"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cult.technology\/wp-json\/wp\/v2\/tags?post=1996"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}30 12 1 * * python3 database_backup_script.py<\/code><\/p>\n
How to Set up cron job in Linux?<\/h2>\n
\n
0 4 * * * python3 \/root\/trending_app_scrapper.py >> \/tmp\/trending_apps_scrapper.log 2>&1<\/code><\/p>\n
How to View all the scheduled Cron jobs?<\/h2>\n
crontab -l<\/code><\/p>\n
Things to keep in mind while configuring Cron jobs<\/h2>\n
\n