1、创建一个test.sh,写入:
/usr/bin/expect << EOF
set timeout 10
spawn sudo -s
expect "*密码*"
send "password\r"
expect "#*"
# send "systemctl status AuthorizeServer\r"
expect
{
"*active (running)*" {}
"" {}
}
# set timeout 3
# send_user "waiting..."
# set timeout 5
expect eof
EOF
2、Dos窗口执行:bash ./test.sh bash后面接test.sh的路径