linux crontab task

You can use the crontab execute a shell script or a series of Linux commands at a specified time, for example, a system administrator to schedule a backup job so that it runs every day.

crontab -e to edit the timing of tasks under the current user

*/15 * * * *  /home/ap/tunnel/command/dbjob/outbound/objob/ob_job_archive_all_10m.sh >> /home/ap/tunnel/command/dbjob/outbound/objob/outbound_runjob.log 2>&1

Ob_job_archive_all_10m.sh tasks performed every 15 minutes, and outputs the result to the log outbound_runjob.log

0 3 * * *  /home/ap/tunnel/command/dbjob/magw/job_magw.sh >> /home/ap/tunnel/command/dbjob/magw/magw_runjob.log 2>&1

Three in the morning every day to perform job_magw.sh script, and outputs the result to /magw_runjob.log log

 

Cron the description

The following is the format of crontab file:

{minute} {hour} {Day-of-month The} {month The} {Day-of-Week} {Full-path-to-the shell-Script} 
O minute: range 0. - 59 
O hour: interval 0--23 
o day-of-month: interval 0 - 31 is 
O month The: interval 1-- 12.1 is January 12 December.. 
O Day-of-Week: interval 0 - 7. Sunday may be 0 or 7.

1. In the 12:01 am run, that every morning a minute. This is an appropriate time to back up, because the system is not loaded.

1 0 * * * /root/bin/backup.sh

2. Every weekday (Mon - Fri) 11:59 pm will be the backup job.

59 11 * * 1,2,3,4,5 /root/bin/backup.sh

The following example and the same effect as the above example:

59 11 * * 1-5 /root/bin/backup.sh

3. Run the command once every 5 minutes

*/5 * * * * /root/bin/check-status.sh

4. The first day of each month 1:10 pm to run

10 13 1 * * /root/bin/full-backup.sh

5. 11 pm every working day to run.

0 23 * * 1-5 /root/bin/incremental-backup.sh

 

Crontab regular tasks encountered problems

1. Timing when calling shell script is not going to carry the current user's environment variables, so in the implementation of bin files need to join the absolute path, such as the implementation of sqlplus time without prompt can not find the path will need to write $ ORACLE_HOME / bin / sqlplus order to be successful. Or at the beginning of the script together. $ HOME / .bash_profile.

2. Execute the script when the report shopt error, because the beginning of the script is / bin / ksh format, to do it. There will be conflicts when $ HOME / .bash_profile, bash and ksh conflict

Guess you like

Origin www.cnblogs.com/mf20140913/p/11824835.html