linux远程设置无外网服务器的系统时间

使用ssh设置服务器时间

ssh root@${hostname}  send "date -s '2022-05-27 00:00:00"

 

使用shell脚本设置服务器:

/usr/bin/expect<<-EOF
spawn ssh root@${hostname}
expect {
"(yes/no)"
{send "yes\r";exp_continue}
"*password"
{send "$password\r"}
}
expect "*]#"
send "date -s '$times'\r"
expect eof
EOF
done

posted @ 2022-05-27 16:18  JesseGod  阅读(224)  评论(0)    收藏  举报