DevOps

How to schedule task with Cron Job ?

What is a cron job ?

Cron Job is a linux server feature which is used to schedule a task to run automatically at a certain time and date.

How to use cron job ?

Following the below given steps , we can use it.

Step 1 : Login your cpanel account with your username and password.

Step 2: Go to advance section and find cron jobs option in this section, click on it.

Cron job cpanel page

 

Step 3: Here you can see the following options.

Cron job Settings page

  1. Common setting select box : here select an option as per your choice. I choose  Once Per Minute(* * * * *)
  2. Minute : Specify here after the how many minutes , you want to execute your cron command.
  3. Hour: Numbers of hour to execute cron command.
  4. Day: If you want to execute your command after few days, specify the number of the days here.
  5. Month: If you want to execute your command after few months, specify the number of months here
  6. Weakday: To run job at a specific weak day, specify that day.
  7. Command: Here write cron command as given below.

 

/usr/local/bin/php -q /home/[cpanel username]/public_html/[file name]

 

Example: 
/usr/local/bin/php -q /home/fz6u5qloh872/public_html/email.php

 

email.php

<?php

mail("mail.happycoder@gmail.com","dotcomcreations.help@gmail.com", "cron job", "cron job message");

?>

 

After one minute scheduled job execute automatically and  you will receive an email from server.

If You feel any difficulty , you can leave it on comment.I will surely answer you.

thanks

About Viren-Dra Yadav

Tech Enthlasis | Open Source Lover | Project Manager and DevOps Developer@EighteenPixels | Mad for Speed
View all posts by Viren-Dra Yadav →

Leave a Reply

Your email address will not be published. Required fields are marked *