
如何编写一个shell脚本,可以自动从服务器A登陆到服务器B,并在服务器B上执行一个操作
以下是我的脚本,但是登陆到服务器B以后,我想是因为服务器B没有这个进程,所以最后一步打包操作并没有在服务器B上执行,请问怎样才能在服务器B上实现最后一步打包的操作。#!/...
以下是我的脚本, 但是登陆到服务器B以后,我想是因为服务器B没有这个进程,所以最后一步打包操作并没有在服务器B上执行,请问怎样才能在服务器B上实现最后一步打包的操作。
#!/bin/bash
... ...
... ...
expect -c "
set timeout 30;
spawn /usr/bin/ssh admin@$ServerB-IP
expect {
\"*yes/no*\" {send \"yes\r\"; exp_continue}
\"*password*\" {send \"xxx\r\";}
}
interact"
tar zcvf ~/hello.tar.gz hello 展开
#!/bin/bash
... ...
... ...
expect -c "
set timeout 30;
spawn /usr/bin/ssh admin@$ServerB-IP
expect {
\"*yes/no*\" {send \"yes\r\"; exp_continue}
\"*password*\" {send \"xxx\r\";}
}
interact"
tar zcvf ~/hello.tar.gz hello 展开
展开全部
expect -c "
set timeout 30;
spawn /usr/bin/ssh admin@$ServerB-IP
expect {
\"*yes/no*\" {send \"yes\r\"; exp_continue}
\"*password*\" {send \"xxx\r\";}
expect {
\"*# \" {send \"tar zcvf ~/hello.tar.gz hello\r\"}
\"*$ \" {send \"tar zcvf ~/hello.tar.gz hello\r\"}
}
interact"
这样试试
set timeout 30;
spawn /usr/bin/ssh admin@$ServerB-IP
expect {
\"*yes/no*\" {send \"yes\r\"; exp_continue}
\"*password*\" {send \"xxx\r\";}
expect {
\"*# \" {send \"tar zcvf ~/hello.tar.gz hello\r\"}
\"*$ \" {send \"tar zcvf ~/hello.tar.gz hello\r\"}
}
interact"
这样试试
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询