自动telnet并且自动运行对方shell。

#!/usr/local/bin/expect -f
set timeout 30
set logname YOUR_LOGIN_ID
set password YOUR_PASSWORD
spawn telnet xxx.xxx.xxx.xxx
expect "login*"
send "$logname\r"
expect "Password:"
send "$password\r"
expect "*$*"        # 针对 prompt 是 xxxx$ 这样的形式,如果是 xxxx# 或 其它,要修改一下
send "ls -l\n"
send "echo haha... nice to me you\n"
send "uname -a \n"
send "who\n"
expect "*$*"
send "exit\n"

你可能感兴趣的:(职场,休闲)