#!/bin/bash
#
sudo echo "ALL ALL=(root)NOPASSWD: /bin/date
ALL ALL=(root)NOPASSWD: /usr/sbin/systemsetup
ALL ALL=(root)NOPASSWD: /usr/bin/sntp" > /etc/sudoers.d/date
sudo chmod 440 /etc/sudoers.d/date
sudo /usr/bin/sntp -sS 10.54.2.2 > /dev/null 2>&1
# 从jsfaq 上的时间进行更新
#formatted_date_time=$(date -r $time_from_jsfaq "+%m%d%H%M%Y.%S")
#sudo date "$formatted_date_time"
username=${HOME##*/} #当前用户的名称
sudo crontab -u $username -l | grep .
notEmpty=$?
sudo crontab -u $username -l | grep /usr/bin/sntp
if [ $? -ne 0 ];then
/usr/bin/expect <<EOF
set timeout 5
spawn crontab -u $username -e
if { $notEmpty == 1 } {
send "i"
} else {
send "G"
send "o"
}
send "*/2 * * * * sudo systemsetup -setusingnetworktime on\r"
send "*/2 * * * * sudo /usr/bin/sntp -sS 10.54.2.2 > /dev/null 2>&1"
send "\x1b:wq\r"
#send ";2R1;95;0c\r"
expect "exit\r"
expect eof
EOF
fi