Linux modify server time update synchronization, and scheduled tasks

Reprinted from: https://blog.csdn.net/lmmilove/article/details/37996149

linux modify server time update synchronization, and timing task
July 20, 2014 20:27:07
readings: 7729
time modification
date month day hour minute year. second
date -s can directly set the system time

For example, the command to set the system time to June 10, 1996 is as follows.

date -s 06/10/96

The command to set the system time to 1:12:00 PM is as follows.

date -s 13:12:00

Time synchronization
1. First of all, you need to understand crontab, a task planning tool in linux.
Crontab can regularly execute the actions you want to do
. Edit
crontab directly with the crontab command -u //Set the cron service of a user. Generally, the root user executes this command When you need this parameter
crontab -l //List the details of
a user's cron service crontab -r //Delete a user's cron service
crontab -e //Edit a user's cron service
Generally use crontab -e to To edit a plan action, the editing mode is the same as the vi editor.
The basic editing format in crontab is as follows
* * * * * command
Time division, day, month, and week commands
. The first column represents minutes 1 to 59 per minute, or /1 is used
. The second column represents Hour 1~23 (0 means 0 o'clock)
3rd column means date 1~31
4th column means month 1~12
5th column ID number week 0~6 (0 means Sunday)
6th column Command to run
crontab file Some examples:
30 21 * * * /etc/init.d/smb restart
The above example means to restart smb every night at 21:30.
45 4 1,10,22 * * /etc/init.d/smb restart
The above example means restarting smb at 4:45 on the 1st, 10th, and 22nd of every month.
10 1 * * 6,0 /etc/init.d/smb restart
The above example means restart smb every Saturday and Sunday at 1:10.
0,30 18-23 * * * /etc/init.d/smb restart
The above example means to restart smb every 30 minutes between 18:00 and 23:00 every day.
0 23 * * 6 /etc/init.d/smb restart
The above example means to restart smb every Saturday at 11:00 pm.
* /1 * * /etc/init.d/smb restart
restart smb every hour
* 23-7/1 * * * /etc/init.d/smb restart
every other hour between 11pm and 7am Hours restart smb
0 11 4 * mon-wed /etc/init.d/smb restart
4th of every month and every Monday to Wednesday at 11:00 smb
0 4 1 jan * /etc/init.d/smb restart
January Restart smb at 4:00 on the 1st
2. Find a network time server, such as some national time service centers
Microsoft Host (United States)
time.windows.com
Taiwan Police University Time Service Center (Taiwan)
asia.pool.ntp.org
Time Service Center of Chinese Academy of Sciences (Xi'an)
210.72.145.44
Netcom Time Service Center (Beijing)
219.158.14.130
3. How do our computers synchronize the time of the time service center
ntpdate asia.pool.ntp.org The
above command is to synchronize the time of
the Let the system synchronize at 23:00 every day, so that you can use the crontab settings above to schedule synchronization with the
following command

crontab -e

Enter crontab editing mode, use the same method as vi,
enter 0 23 * * * ntpdate asia.pool.ntp.org >> /var/log/ntpdate.log
save and exit
This completes your system to go to asia at 23:00 every day. pool.ntp.org synchronizes the time and puts the synchronized log in
/var/log/ntpdate.log

Let's add the system time setting
date -s to set the system time directly. For
example , the command to set the system time to June 10, 1996 is as follows.

date -s 06/10/96

The command to set the system time to 1:12:00 PM is as follows.

date -s 13:12:00

Note that what is said here is the system time, which is maintained by the operating system in Linux.
When the system is started, the Linux operating system reads the time from the CMOS into the system time variable, and later the time is modified by modifying the system time. In order to keep the system time consistent with the CMOS time, Linux writes the system time to the CMOS at regular intervals. Since the synchronization is performed at regular intervals (about 11 minutes), after we execute date -s, if the machine is restarted immediately, the modification time may not be written into the CMOS, which is the cause of the problem. If you want to make sure the modification takes effect, you can execute the following command.

clock -w

This command forces the system time to be written to CMOS

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325686558&siteId=291194637
Recommended