登陆ssh脚本

#!/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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值