expect实现命令行自动交互
文件名:loginServerByExpect.exp
#!/usr/bin/expect -f
#记录日志
log_file -noappend "/data/log/expect.log"
set timeout 30
# 密码通过参数传递
set password [lindex $argv 0]
spawn ssh root@master-evm1
expect "password:"
send "$password\r"
#进入交互模式
interact使用方法:
chmod a+x loginServerByExpect.exp
./loginServerByExpect.exp thisispassword