作者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
→ cobrasgo:你file B不是只echo字串而已嗎? 04/12 23:55
→ imio24:sorry 不是字串 是call `./A.sh` 04/13 14:23
→ alongalone:為什麼在B裡面寫 sh ./A.sh 這樣就好 ? 04/13 14:29
→ alongalone: 不 04/13 14:29
→ lulala453:不考慮把A server 的public key 放至 B server嗎? 04/21 13:19
推 Killercat:ssh-copy-id 不過好像不是每個發行版都有 04/24 06:37
→ Killercat:反正那也只是個小script 找個有的拷來用就好 04/24 06:37