[問題] 用ssh 傳檔去執行

看板LinuxDev作者 (imio)時間12年前 (2013/04/12 21:09), 編輯推噓1(106)
留言7則, 5人參與, 最新討論串1/1
請問我想用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

04/12 23:55, , 1F
你file B不是只echo字串而已嗎?
04/12 23:55, 1F

04/13 14:23, , 2F
sorry 不是字串 是call `./A.sh`
04/13 14:23, 2F

04/13 14:29, , 3F
為什麼在B裡面寫 sh ./A.sh 這樣就好 ?
04/13 14:29, 3F

04/13 14:29, , 4F
    不
04/13 14:29, 4F

04/21 13:19, , 5F
不考慮把A server 的public key 放至 B server嗎?
04/21 13:19, 5F

04/24 06:37, , 6F
ssh-copy-id 不過好像不是每個發行版都有
04/24 06:37, 6F

04/24 06:37, , 7F
反正那也只是個小script 找個有的拷來用就好
04/24 06:37, 7F
文章代碼(AID): #1HQ0U1Lc (LinuxDev)
文章代碼(AID): #1HQ0U1Lc (LinuxDev)