说明:
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 [email protected]$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
时间: 2024-12-14 06:08:38