安装expect
sudo apt install expect
编写脚本
touch $HOME/.monitor_auto_test && chmod +x $HOME/.monitor_auto_test
vim $HOME/.monitor_auto_test
#!/usr/bin/expect
set timeout 30
#窗口调整
trap {
set rows [stty rows]
set cols [stty columns]
stty rows $rows columns $cols < $spawn_out(slave,name)
} WINCH
#端口 ip
spawn ssh -l root -p xx(端口) xxx.xxx.xxx.xxx(ip)
expect {
"(yes/no?" {
send "yes\n"
expect "*password:"
#password
send "xxxxxxxxx\r&