Skip to main content

What is CronTab? What does it do?



What if you want to execute a file daily at particular time?Running it manually daily is 
absolutely not a good idea..! 
Then What do you do?For this kind of manual works,To Automate it,
there is a daemon in linux called "CRONTAB".

Crontab:            

Crontab called as CRON TABle Where 
cron is a daemon to run periodically on a given time and Table consists of scheduled tasks,
jobs 
i.e, Crons.

Crontab Options: 
 
crontab -l : lists all the crontabs scheduled.                                                    
crontab -e : Edits existing cron or else create new cron.                                    
crontab -r : Removes scheduled cron jobs.                                                  
crontab -i -r: Prompts before deleting user's crontab i.e,asks your permission. 
crontab -u username -l : lists all the crons of a particular user. 
 
Setting up a cron:
Press Ctrl+Alt+t to open the terminal and paste following command.
 
crontab -e  
 
Syntax : 
 
 *         *        *                *           *  /home/SendEmail.php 
 
 * means: 
 
 (minute)   (hour)    (day of month)   (month)   (day of week)  /Path_of_the/file/to_be_executed
 
Allowed Values: 
 
(0-59)     (0-23)    (1-31)           (1-12)     (0-6) 
  
->Above cron runs run for every minute
 
What is the difference between day/month and day/week? 
If Day/Month : 5 and Day/Week :5 then cron gets executed on 5th date of specified month 
and 5th(Friday) of every week in the specified month. 
 Day/Month is Once a Month. 
 Day/Week is 4 times i.e, no.of weeks in a month having friday.
 
Cron Special keywords:

@yearly (or) @manually - Runs once a yearly at 12.00 AM on January 1st.
@monthly               - Runs once every month 1st at 12.00 AM. 
@weekly                - Runs once a week at 12.00 AM on Sunday.
@daily                 - Runs once daily at midnight 12.00AM 
@hourly                - Runs once an hour at the start.
@reboot                - Runs on starting up the system. 

 Where does crontab present in linux  OS? 
 Linux      :    /var/spool/cron/crontabs/   
Try examples here..                https://crontab.guru/  
 
Examples: 

MinuteHour      Day/Month Month      Day/Week  Executes at                                           
*****At every minute.
4511-18**1-6At minute 45 past every hour from 11 through 18 on every day-of-week from Monday through Saturday.
5,4512,3*1-51-5At minute 5 and 45 past hour 12 and 3 on every day-of-week from Monday through Friday in every month from January through May.  

Comments

Popular posts from this blog

Send Email(with subject,body,attachment) using SSMTP through Terminal in linux?

1.Install ssmtp as              $ sudo apt-get update && sudo apt-get install ssmtp 2.Configure smtp file by editing the following file as, $ sudo gedit /etc/ssmtp/ssmtp.conf Update file with the following: AuthUser=Sendermail@gmail.com AuthPass=SenderPasswordforGMAIL FromLineOverride=YES mailhub=smtp.gmail.com:587 UseSTARTTLS=YES Now ssmtp.conf file should look like as the following one, AuthUser=Sendermail@gmail.com AuthPass=SenderPasswordforGMAIL # # Config file for sSMTP sendmail # # The person who gets all mail for userids < 1000 # Make this empty to disable rewriting. root=postmaster # The place where the mail goes. The actual machine name is required no # MX records are consulted. Commonly mailhosts are named mail.domain.com mailhub=smtp.gmail.com:587 # Where will the mail seem to come from? #rewriteDomain= # The full hostname hostname=tele-desktop118 # A...

Backup (or) Download MYSQL Database as a zip file Using PHP

NOTE:Please change below credentials  with respect to your Database and Run the file. <?php define ( "DB_USER" ,  'DatabaseUSERNAME' ); define ( "DB_PASSWORD" ,  'DatabasePASSWORD' ); define ( "DB_NAME" ,  'DatabaseNAME' ); define ( "DB_HOST" ,  'localhost' ); define ( "BACKUP_DIR" ,  'myphp-backup-files' );  // Comment this line to use same script's directory ('.') define ( "TABLES" ,  '*' );  // Full backup //define("TABLES", 'table1, table2, table3'); // Partial backup of required tables define ( "CHARSET" ,  'utf8' ); define ( "GZIP_BACKUP_FILE" ,  true );   // Set to false if you want plain SQL backup files (not gzipped) class  Backup_Database {     var  $host ;     var  $username ;   ...

How to Integrate SMS API's with PHP?

<?php $message  =  "Happy Coding..A Test Message to Check API" ; $students  =  "9999999999"  //your mobile number to test $msg  =  urlencode ( $message );          $url = "http://www.bulksmsapps.com/api/apibulkv2.aspx?apikey=XXX-XXXX-XXXX-XXX-XXXXXXXX&sender=XXXXX&number=" . $students . "&message=" . $msg ; $curl_handle = curl_init (); curl_setopt ( $curl_handle , CURLOPT_URL , $url ); curl_setopt ( $curl_handle , CURLOPT_RETURNTRANSFER , 1 );  curl_setopt ( $curl_handle ,  CURLOPT_FOLLOWLOCATION ,  false ); set_time_limit ( 0 ); $response  =  curl_exec ( $curl_handle ); err  =  curl_error ( $curl_handle ); curl_close ( $curl_handle ); if ( $err ) {     echo  "cURL Error #:"  .  $err ; } else {     echo  $response ; } ?> ...