Crontab and the server synchronization time every 15 minutes

Source: Internet
Author: User

Crontab: crontab permission: syntax of the root user and the owner of the crontab file: crontab [-e [UserName] |-l [UserName] |-r [UserName] |-v [UserName] | File] Description: crontab is used to allow users to run programs at a fixed time or interval. In other words, it is similar to the user's time table. -U user is used to set the time table of the specified user. The premise is that you must have the permission (for example, root) to specify the time table of another user. If-u user is not used, the time table is set. Parameter:-e [UserName]: run the text editor to set the time table. The preset text editor is VI. If you want to use another text editor, set the VISUAL environment variable to specify the Text Editor (for example, setenv VISUAL joe)-r [UserName]: Delete the current time table-l [UserName]: list the current time series table-v [UserName]: the format of the time series table listing the user's cron job status is as follows: f1 f2 f3 f5 program where f1 represents minutes, f2 represents hours, f3 indicates the day of a month, f4 indicates the month, and f5 indicates the day of a week. Program indicates the program to be executed. When f1 is *, the program is executed every minute. If f2 is *, the program is executed every hour, and so on, when f1 is a-B, it indicates that it will be executed from minute a to minute B, when f2 is a-B, it indicates that execution is performed from hour a to hour B, and when f1 is */n, it indicates that execution is performed every n minutes, if f2 is */n, the task is executed every n hours. If f1 is a, B, c ,... a, B, c ,... execute in minutes. f2 is a, B, c ,... a, B, c... you can save all settings in the file and use crontab file to set the time table. Some syntaxes vary due to different unix versions. For example, if the */n method is used to set the interval for execution in hp unix aix, a syntax error occurs. In such unix, the execution interval can only be listed. For more information, see the example. Usage: Use VI to edit a cronfile file, and then enter a time table in good format in the file. After editing, save and exit. Enter $: crontab cronfile in the command line to submit the cronfile file to the c r o n process, a copy of the newly created cronfile has been stored in the/v a r/s p o l/c r o n directory. The file name is the user name. Example: Execute the command once every 0th minutes of every hour every month/bin/ls: 0 *****/bin/ls from to every day within January 1, December, run Once every 20 minutes/usr/bin/backup: */20 6-12*12 */usr/bin/backup from Monday to Friday send a letter to alex@domain.name at every day: 0 17 ** 1-5 mail-s "hi" alex@domain.name </tmp/maildata every day at midnight 00:20, 02:20, 04:20 .... execute echo "haha" 20 0-23/2 *** echo "haha" every two hours from PM to am, 8 * date is executed every 20 minutes in hp unix, which indicates: 0, 20, 4 0 * instead of */n. Otherwise, a syntax error occurs. Note: When the program is executed at the specified time, the system will send you a letter, display the content of the program. If you do not want to receive such a message, add>/dev/null 2> & 1 after each line is empty. 15-minute server synchronization time */15 * root/usr/sbin/timesync. sh do one thing at every night 30 0 * root/var/wwwroot/pay-reminder/trunk/src/questionaire/processQuestionaireDeadline. sh>/tmp/processQuestionaireDeadline. log Note: timesync. sh must have the execution permission, that is, chmod 777 timesync. shtimesync. sh Script :#! /Bin/bashecho "Sync start... ">/var/log/timesync. logdate>/var/log/timesync. log # using China standard time serverntpdate 210.72.145.44 218.21.130.42 # synchronize hardware clockhwclock -- systohcdate>/var/log/timesync. logecho "Sync End. ">/var/log/timesync. log

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.