GeekAfterHours
  • How To
    • Plenty of Fish Search Without Registering
    • How to Hide Text Messages on iPhone?
  • Login Guide
    • How to Login (UKGPro) Ultipro Employee from Home (Mobile and Desktop)
    • wmlink/2step on a Walmart
    • DISH Anywhere
    • Walmart GTA Portal
    • Uinteract Login
    • myOLSD Portal
    • Paycor Login
    • Dayforce Trader Joes Login
    • My Office Tupperware Login
    • MyHR BFUSA MyBridgeStone Portal Login
    • AHRebates.com Rebate Form Submission & Reward Guide
    • MyTHDHR Your Schedule Login
    • OurTime Login
    • MyHTSpace Login
  • Gadgets
    • Best Projectors for Gaming
    • Best Cardstock Printers
    • Best Smartwatches for Texting
    • Best Headphones for Music Production Artists
    • Best 3D Printer for Cosplay
    • Best Tablet for OSU
    • Best Power Supply for GTX 1080 Ti
    • Best Monitor for GTX 1070
    • Best Walkie Talkie
    • Best Satellite Phone for Backpacking
  • Laptops
    • Best Laptops for Zoom Meetings
    • Best Laptops for Medical Students
    • Best Laptops for Online Schooling
    • Best Laptops for College Students
    • Best IPS Screen Laptops
    • Best Laptops for Machine Learning
    • Best Laptops for Revit Software
    • Best Laptops with Microsoft Office Bundle
    • Best Laptops for Adobe Creative Cloud
    • Best Laptops for Stock Trading
    • Best Laptops for League of Legends
    • Best Laptops for Mechanical Engineering Students
    • Best Laptops for Cricut Maker Cutting Machine
    • Best Laptops for Accounting
  • Guides
    • Best YouTube to Mp4 Converters Online
  • About Us
No Result
View All Result
  • How To
    • Plenty of Fish Search Without Registering
    • How to Hide Text Messages on iPhone?
  • Login Guide
    • How to Login (UKGPro) Ultipro Employee from Home (Mobile and Desktop)
    • wmlink/2step on a Walmart
    • DISH Anywhere
    • Walmart GTA Portal
    • Uinteract Login
    • myOLSD Portal
    • Paycor Login
    • Dayforce Trader Joes Login
    • My Office Tupperware Login
    • MyHR BFUSA MyBridgeStone Portal Login
    • AHRebates.com Rebate Form Submission & Reward Guide
    • MyTHDHR Your Schedule Login
    • OurTime Login
    • MyHTSpace Login
  • Gadgets
    • Best Projectors for Gaming
    • Best Cardstock Printers
    • Best Smartwatches for Texting
    • Best Headphones for Music Production Artists
    • Best 3D Printer for Cosplay
    • Best Tablet for OSU
    • Best Power Supply for GTX 1080 Ti
    • Best Monitor for GTX 1070
    • Best Walkie Talkie
    • Best Satellite Phone for Backpacking
  • Laptops
    • Best Laptops for Zoom Meetings
    • Best Laptops for Medical Students
    • Best Laptops for Online Schooling
    • Best Laptops for College Students
    • Best IPS Screen Laptops
    • Best Laptops for Machine Learning
    • Best Laptops for Revit Software
    • Best Laptops with Microsoft Office Bundle
    • Best Laptops for Adobe Creative Cloud
    • Best Laptops for Stock Trading
    • Best Laptops for League of Legends
    • Best Laptops for Mechanical Engineering Students
    • Best Laptops for Cricut Maker Cutting Machine
    • Best Laptops for Accounting
  • Guides
    • Best YouTube to Mp4 Converters Online
  • About Us
No Result
View All Result
GeekAfterHours
No Result
View All Result
Home How To

Cron Job: How to Setup and Schedule Commands

Daniel by Daniel
August 24, 2021
Cron Job
Table of contents
  • What is a Corn Job?
    • Elements
  • Cron Job Setup Using cPanel
  • Why Use It?
  • How to Prevent Cron Job Collision?
    • Conclusion

In this article we are going to talk about Cron Jobs from the scratch. We will discuss several Cron Job related topics like what exactly it is, how to it setup up and much more.

So, here we go…

What is a Corn Job?

Cron job is a Linux utility.

With the help of Cron Jobs a Linux user can schedules a command or task to be executed sometime in the future.

For automate monotonous tasks, it is a useful feature.

So, these scheduled tasks or commands are known as Cron jobs.

With this feature you can easily schedule backups, deleting files, and many other important tasks as well.

Cron jobs scripts that are generally executed are used to modify files or databases.

Other tasks like sending email notifications or that do not modify on the server are also done.

Setting Cron Jobs to run by minute, hour, day of the week, day of the month, month or any of these combinations is also possible.

Elements

  1. The script that is to be called or executed.
  2. The command that executes the script on a recurring basis (typically set in the cPanel).
  3. The action or output of the script (which depends on what the script being called does).

A general format of a cron job is –

Minute(0-59) Hour(0-24) Day_of_month(1-31) Month(1-12) Day_of_week(0-6) Command_to_execute

Cron Job Setup Using cPanel

cPanel is a Linux-based Graphical User Interface (GUI), and today we are going to use it to set a corn job.

Here’s how you can do it –

1) First log in to cPanel.

2) Now search for Cron Job from the dashboard or go to the Advanced menu option and click on Cron jobs.

3) After that you will have to select an email where you’d like to receive Cron output.

4) Next simply leave the email address listed beside Current Email if its valid.

5) In case you wish to use a different email id then enter the id into the form field next to Email and click Update Email once you have finished.

6) Next in the Add New Cron Job section, you can give the command that you wish to run along with its frequency.

7) Here you can list either Linux commands or a file that you want to run at a specific time.

8) Now go to the field labelled Common Settings.

9) Here select the frequency that you would like to run from the options at the drop-down menu.

[su_highlight]Note: This will also update time settings according to your choice.[/su_highlight]

10) Frequency can also be adjusted easily, and Month, Date, Hour and Weekday can also be changed.

11) Click on Add new Cron Job option after you are done making your selections.

Now you have successfully scheduled a command using the Cron Jobs tool within cPanel.

Let us now discuss some examples of commands –

The format to run a Cron Job every minute is:

* * * * * <command-to-execute>

The format to run a Cron Job at every 5th minute is:

*/5 * * * * <command-to-execute>

The format to run a Cron Job at everyquarter hour or 15th minute is:

*/15 * * * * <command-to-execute>

The format to run a Cron Job atevery hour at minute 30 is:

30 * * * * <command-to-execute>

With the help of commas, you can also select multiple time intervals:

0,5,10 * * * * <command-to-execute>

To run a Cron Job everyday:

0 0 * * * <command-to-execute>

Run it every 2 hours:

0 */2 * * * <command-to-execute>

To run a cron job every month:

0 0 1 * * <command-to-execute>

To run a cron job at a specific time of the month:

5 0 * 4 * <command-to-execute>

Run a cron job every 6 months:

0 0 1 */6 * <command-to-execute>

To run cron job every year:

0 0 1 1 * <command-to-execute>

To run a cron job every Sunday:

0 0 * * SUN <command-to-execute>

To run a cron job at 3 am, everyday:

0 3 * * * <command-to-execute>

So here were 13 examples that will help you schedule tasks.

With the above guide you might have now understood the basic usage of Cron Job at Linux system.

Why Use It?

The usage of Cron Jobs has been immense for many users, but let us discuss some relevant usage such as –

  1. One of the most effective of corn job is to regularly deactivate or delete accounts. This is mostly used for accounts with membership, where after the expiration date, you can set Cron job to deactivate it for no further chargers.
  2. Sending of daily newsletter e-mails with Cron Jobs become an easy task.
  3. With the help of Cron Jobs you can easily erase cached data files in regular intervals.
  4. Checking your website for broken links is also possible with Cron Jobs.
  5. Scheduling tasks to run from a command line script can be done, rather than using web script to run it.
  6. Easy tasks like fetching your most recent Tweets and put it in specific text files is also done by Cron Jobs.

How to Prevent Cron Job Collision?

As many Cron job runs together, you will not want any of them to collide if they are taking longer time to run than the frequency itself.

Let’s consider an example, that you have a cron Job set to run every minute but sometimes it might take longer than a minute to run.

This can result in the same cron script to run before the previous one.

Due to this too many processes can run which can result in a possible crash in the server.

Well, you can solve it with the help of file locking or non-blocking (LOCK_NB) type of file locks.

By adding this command to the corn job script you can use file locking.

$fp = fopen(‘/tmp/lock.txt’, ‘r+’);

if(!flock($fp, LOCK_EX | LOCK_NB)) {

echo ‘Unable to obtain lock’;

exit(-1);

}

/* … */

fclose($fp);

When you use file locking, they basically block the script if there is an existing lock.

They would also release after the lock doesn’t exist anymore.

Conclusion

So, that all for Cron Jobs. Hope this article was helpful and gave you a subtle understanding of this scheduling command feature.

Now give it a try and starting using Cron job, by scheduling tasks on your system.

Daniel

Daniel

Daniel is inspired by innovative technology taking shape around the world and this is what motivated him to start Geek After Hours, a tech blog featuring how to guides about computer, laptops, mobiles, software, and gadgets. He also like to write reviews about technology products with an aim to help you make better buying decisions.

Related Posts

Gray Box On Snapchat

Grey Box On Snapchat: Myth Or Legend? What Exactly Does It Grey Box Mean On Snapchat 

by Charlotte
January 23, 2023
0

...

Why Can’t I See Comments on Facebook & How Fix It?

Why Can’t I See Comments on Facebook & How Fix It?

by Charlotte
January 16, 2023
0

...

How to Pin Any Tweet on Your Twitter Profile

How to Pin Any Tweet on Your Twitter Profile (Someone Else’s Tweets Also)?

by Daniel
December 4, 2022
0

...

A man presenting on the white board.

How To Incorporate Personal Branding In Your Guest Post?

by Deepak
December 15, 2022
0

...

A Few Things which every Essay Writer Needs to Follow

A Few Things which every Essay Writer Needs to Follow

by Daniel
October 10, 2022
0

...

gah-logo

Affiliate Disclaimer

Geek After Hours is a participant in the Amazon Services LLC Associates Program which is an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com.

Best Cameras

Best Low Light Video Cameras (Value for Money)

10 Best Cameras for Filmmaking on a Budget

5 Best Cameras for Stop Motion Photography (Expert Choice)

5 Best 16mm Lens Cameras (Tested by Professional Photographers)

4 Best Ice Fishing Cameras (Expert’s Opinion)

(Top3) Best 360 Camera for Real Estate Reviews (According to Experts)

Best Laptops

10 Best Laptops Under $800

7 Best Gaming Laptops Under $600

13 Best Gaming Laptops Under $1500 (Top Picks)

Best Gaming Laptops Under 2000 Dollars (Top Picks)

Six Play-To-Earn Online Games To Consider In Your Free Time

Different Ways You Can Use Cryptocurrencies In The NHL Industry

  • About Us
  • Contact Us
  • Disclaimer
  • Privacy Policy
  • Terms
  • Write for us

© 2022 GeekAfterHours. All Rights Reserved

No Result
View All Result
  • How To
  • Login Guide
  • Gadgets
  • Laptops
  • Guides
  • UKG PRO ULTIPRO

© 2022 GeekAfterHours. All Rights Reserved