#!/usr/bin/expect -f set timeout 30 spawn ssh myname@x.x.x.x expect "password:" send "r0Iz9@o!*&9io_P#Fi&1*\r" expect "]*" send "projectname\r" send "ssh test2\r" interact
这是两个ssh的过程,先从本地ssh到x.x.x.x,然后从x.x.x.x以projectname再ssh到test2
expect 后表示终端显示的文字
send 表示 我打的命令 \r 表示回车
本地运行服务器上某个脚本,运行完毕后退出ssh
#!/usr/bin/expect -f set timeout 30 spawn ssh username@x.x.x.x expect "password:" send "r0Iz9123&9io_P#Fi&1*\r" expect "]*" send "xxxx\r" send "ssh test\r" send "cd /data/sites/stg/project\r" send "python scripts/test/test_api.py\r" send "exit\r" expect "Connection to test closed." send "exit\r" send "exit\r" interact