Crontab can perform the actions you want to do regularly.
Edit directly with crontab command
Crontab-u//Set a user's Cron service, which is required by the general root user when executing this command
CRONTAB-L//list details of a user's cron service
Crontab-r//Delete a user's cron service
CRONTAB-E//Edit a user's cron service
Some examples of crontab files:
code is as follows |
copy code |
* * */ETC/INIT.D/SMB Restart The example above shows 21:30 restart SMB per night. 4 1,10,22 * */ETC/INIT.D/SMB Restart The above example represents 4:45 restart SMB for 1, 10, 22nd per month. 1 * * 6,0/ETC/INIT.D/SMB Restart The above example indicates 1:10 restart SMB per Saturday and Sunday. 0,30 18-23 * * */ETC/INIT.D/SMB Restart The above example indicates that SMB is restarted every 30 minutes between 18:00 and 23:00 every day. 0 * * * 6/ETC/INIT.D/SMB Restart The example above indicates that the 11:00 PM restarts SMB every Saturday. * */1 * * */ETC/INIT.D/SMB restart Restart SMB per hour * 23-7/1 * * */etc/init.d/smb restart 11 o'clock to 7 in the morning, every Restart SMB 0-4 * mon-wed/etc/init.d/smb Restart Monthly 4th with 11-point restart SMB for every Monday to Wednesday 0 4 1 Back-/ETC/INIT.D/SMB Res Tart January 1 4 restart SMB |
Attached to the crontab outside the following is the additional method
Two ways
First, you can sync from the time server time.nist.gov.
Add in Vi/etc/crontab:
The code is as follows |
Copy Code |
0 1 * * Root rdate-s time.nist.gov Time.nist.gov is a time server. |
Second, build yourself a time server (192.168.10.1)
The code is as follows |
Copy Code |
1). # RPM-IVH ntp-4.1.2-4.el3.1.i386.rpm RPM-IVH ntp-4.2.0.a.20040617-4.el4.1.i386.rpm 2). # vi/etc/ntp.conf Comment Line Restrict default Ignore Join a line Restrict 192.168.10.0 mask 255.255.255.0 notrust nomodify |
3). # Vi/etc/ntp/step-tickers
Join a line
pool.ntp.org
This will automatically connect to the international Standard Time server each time the ntpd is started;
4). # Service NTPD Start
5). # Netstat-an |grep 123
Make sure that the port is open in UDP
Time Client Configuration (192.168.10.2)
The code is as follows |
Copy Code |
1). # ntpdate 192.168.10.2 Should show sync success 2). # CROND-E Join 0-59/60 * * * */usr/sbin/ntpdate 192.168.10.1 10.31.0.53 |
Indicates that time is synchronized every 10 minutes
How to set time synchronization between servers
Posted in operating System on April 11th, 2006
The time between the servers of the HP-UX system needs to be synchronized, and the ntpd can be achieved with a good purpose.
Suppose we want to host1 as a time server, Host2 regularly to synchronize with host1 system time, then need to make the following settings, all with the root user execution.
1. Set up host1 machine
Edit/etc/rc.config.d/netdaemons, modify the line below
The code is as follows |
Copy Code |
Export ntpdate_server=– because this machine will serve as the server, this parameter remains null Export xntpd=1– defaults to 0, and 1 indicates that the NTP process will start automatically with system startup Export xntpd_args= |
Edit/etc/ntp.conf, add the following line
This file is all annotated by default and can be read as an NTP document, and we only need to add at the end that the local system time will be used as the server time
The code is as follows |
Copy Code |
Server 127.127.1.1 Fudge 127.127.1.1 Stratum 10 Start the NTP daemon /SBIN/INIT.D/XNTPD start |
Check process status
Ntpq-p
2. Set up Host2 machine
Edit/etc/rc.config.d/netdaemons, modify the line below
The code is as follows |
Copy Code |
Export ntpdate_server=host1– because this machine will be the client, this parameter is set to the server machine name Host1 Export xntpd=1 Export xntpd_args= |
Edit/etc/ntp.conf, add the following line
The code is as follows |
Copy Code |
Server host1 driftfile/etc/ntp.drift– can be interpreted as caching files, reducing network traffic to the NTP server |
Create Driftfile
The code is as follows |
Copy Code |
Touch/etc/ntp.drift |
Test synchronization because NTPD startup takes a long time, about 6 minutes, so it takes a while to test
Ntpdate host1
The normal output should be as follows
Apr 13:35:38 ntpdate[27692]: Adjust time server 10.48.52.5 offset-0.002519 SE
If the report server cannot find an error no server www.111cn.net suitable for synchronization found, it is usually because the firewall is set between the machines, and you can try to use the-u option for ntpdate
Ntpdate-u host1
If still not, I'm afraid only the network administrator to open the firewall port that ntpdate need.
After the test is successful, start the NTP daemon so that the system automatically synchronizes with the server on a regular basis. Of course, we can also use cron to manually specify synchronization times, such as setting the following script at 2 o'clock in cron every night, or you can do it.
The code is as follows |
Copy Code |
#!/sbin/sh Logdir=/tmp logfile= "$LOGDIR/ntpdate.log"
|
/usr/sbin/ntpdate-u host1 | Tee-a $LOGFILE
Add the system time settings below
Date-s can set system time directly
For example, set the system time to the June 10, 1996 command as follows.
#date-S 06/10/96
The command to set the system time to 1:12 P.M. 0 seconds is as follows.
#date-S 13:12:00