作者imio24 (imio)
看板LinuxDev
标题[问题] 用ssh 传档去执行
时间Fri Apr 12 21:09:19 2013
请问我想用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"
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 71.190.171.54
1F:→ cobrasgo:你file B不是只echo字串而已吗? 04/12 23:55
2F:→ imio24:sorry 不是字串 是call `./A.sh` 04/13 14:23
3F:→ alongalone:为什麽在B里面写 sh ./A.sh 这样就好 ? 04/13 14:29
4F:→ alongalone: 不 04/13 14:29
5F:→ lulala453:不考虑把A server 的public key 放至 B server吗? 04/21 13:19
6F:推 Killercat:ssh-copy-id 不过好像不是每个发行版都有 04/24 06:37
7F:→ Killercat:反正那也只是个小script 找个有的拷来用就好 04/24 06:37