##免交互SSH登陸
auto_login_ssh () {
expect -c "set timeout -1;
spawn -noecho ssh -o StrictHostKeyChecking=no $2 ${@:3};
expect *assword:*;
send -- $1\r;
interact;";服務器
示例:ssh
auto_login_ssh 密碼 用戶名@IP "sh /root/wangfeng/check.sh" >>/root/wangfeng/tmp/test.txt
cat /root/wangfeng/tmp/test.txtspa
執行遠端服務器 /root/wangfeng/check.sh 腳本,輸出返回至本地 /root/wangfeng/tmp/test.txtblog