标签:expect
带账号、密码ssh的脚本
说明:
1、为expect脚本,后缀建议用.exp(写.sh也没关系)
2、执行需用expect命令
3、登录后可执行想要的命令
$ cat /usr/local/bin/ssh.exp
#!/usr/bin/expexct -f
set ip [lindex $argv 0]
set timeout 10
spawn ssh aa@$ip
expect {
"*(yes/no)*" { send "yes\r"; exp_continue}
"Password:" { send "********\r" }
}
expect "$*"
send "ifconfig | grep addr:10 | cut -b 16-32\r"
send "hostname\r"
send "who | grep MING | head -n 1\r"
send "exit\r"
expect eof
:wq
本文出自 “linux” 博客,请务必保留此出处http://yangzhiming.blog.51cto.com/4849999/1902128
标签:expect
原文地址:http://yangzhiming.blog.51cto.com/4849999/1902128