[问题] 用ssh 传档去执行

楼主: imio24 (imio)   2013-04-12 21:09:19
请问我想用ssh 传一档案从 A server 到 B server执行
所有指令写在档案fileA 执行ok 但是我用fileB 去执行file A
他却会在前一行个expect还没执行完就执行下一行我试了interact and expect eof都不行
我应该如何写 谢谢
file A
#!/bin/bash
echo "start"
expect -c 'set timeout 5; spawn -noecho ssh -o StrictHostKeyChecking=no 'user'@'ip' mkdir 'dir'; expect *password:*; send "'passwd'\r"; interact'
expect -c 'set timeout 5; spawn -noecho scp -o StrictHostKeyChecking=no 'file' 'user'@'ip':'RemoteTMPDir'/; expect *password:*; send "'passwd'\r"; interact'
expect -c 'set timeout 5; spawn -noecho ssh -o StrictHostKeyChecking=no 'user'@'ip' bash -s < 'file'; expect *password:*; send "'passwd'\r"; interact'
expect -c 'set timeout 5; spawn -noecho ssh -o StrictHostKeyChecking=no 'user'@'ip' rm -f 'file'; expect *password:*; send "'passwd'\r"; expect eof'
echo "done"
file B
#!/bin/bash
echo "./A.sh"
作者: cobrasgo (人鱼线变成鲔鱼线,超帅)   2013-04-12 23:55:00
你file B不是只echo字串而已吗?
楼主: imio24 (imio)   2013-04-13 14:23:00
sorry 不是字串 是call `./A.sh`
作者: alongalone (沿着孤单的路)   2013-04-13 14:29:00
为什么在B里面写 sh ./A.sh 这样就好 ?    不
作者: lulala453   2013-04-21 13:19:00
不考虑把A server 的public key 放至 B server吗?
作者: Killercat (杀人猫™)   2013-04-24 06:37:00
ssh-copy-id 不过好像不是每个发行版都有反正那也只是个小script 找个有的拷来用就好

Links booklink

Contact Us: admin [ a t ] ucptt.com