腳本執行時,需要輸入交互"y",用expect可以實現交互輸入過程;
#!/usr/bin/expect -f set ipaddr [lindex $argv 0] set port "23000" spawn -noecho ssh -p $port root@$ipaddr expect { -re "\]# " { send "bash /data/app/lhzs/public/script/checksvr.sh\n" expect { -re "\]: " { send "y\n" exp_continue } -re "\]# " { send "exit\n" } } } } expect eof exit