1.写一个shell script
#vi settime.sh
##########################################
#!/bin/bash
net time set -I 192.168.0.2
##########################################
#没有内网用外网的
#!/bin/bash
#ntpdate 网址
# ntpdate 210.72.145.44
210.72.145.44是中国国家授时中心的官方服务器
将这个文件保存到/usr/bin/settime.sh 这个地址随便的 文件名也是随便的,但不要用系统命令,不然冲突
3.更改文件属性
chmod +x /usr/bin/settime.sh
4.添加一个作业
#vi settime.sh
##########################################
#!/bin/bash
net time set -I 192.168.0.2
##########################################
#没有内网用外网的
#!/bin/bash
#ntpdate 网址
# ntpdate 210.72.145.44
210.72.145.44是中国国家授时中心的官方服务器
将这个文件保存到/usr/bin/settime.sh 这个地址随便的 文件名也是随便的,但不要用系统命令,不然冲突
3.更改文件属性
chmod +x /usr/bin/settime.sh
4.添加一个作业
#crontab -e
*/5 * * * * settime.sh 2>&1> /dev/null
每五分钟执行一次
注:装了samba 才可以使用 net 命令 yum install samba
装了NTP 才能用ntpdate yum install ntp
转载于:https://blog.51cto.com/frankzhao/253395