带账号、密码ssh的脚本
说明:
1、为expect脚本,后缀建议用.exp(写.sh也没关系)
2、执行需用expect命令
3、登录后可执行想要的命令
$ cat /usr/local/bin/ssh.exp
#!/usr/bin/expect -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博客51CTO博客,原文链接http://blog.51cto.com/yangzhiming/1902128如需转载请自行联系原作者
yangzhimingg