以下是两个脚本请注意.。。。方便以后查看特此记录下
[root@localhost ~]# cat 1 3 #!/usr/bin/expect -f set port 22 set user salt set host 127.0.0.1 set password 111111 set timeout -1 spawn ssh -p$port $user@$host expect "*password:*" send "$password\r" expect "*#*" { send "ip a ;df -h ;free -m;echo ok \r" } expect "*ok*" {send "echo \"test return value\" \r"} expect eof #!/usr/bin/expect set PORT [lindex $argv 0] set IP [lindex $argv 1] set USER [lindex $argv 2] set PASSWD [lindex $argv 3] spawn ssh -p$PORT $USER@$IP ip a expect { "yes/no" { send "yes\n" expect "password" send "$PASSWD\n" } "password:" { send "$PASSWD\n" } } expect eof #interact
转载于:https://blog.51cto.com/kkkkkk/1301073