获取服务器ip的时间,再通过date -s 设置本地服务器时间
set_local_time(){
echo "set time now"
# get time from $USER@ip
time=`ssh $USER@ip "date '+%Y-%m-%d %H:%M:%S'"`
expect << EOF
spawn sudo date -s "$time"
expect {
"*hddl*" { send "xxxxxx\r" }
}
expect eof
EOF
local_time=`date '+%Y-%m-%d %H:%M:%S'`
echo "Local time set success: $local_time"
}