簡體   English   中英

預期腳本中的bash命令重定向失敗,權限被拒絕(spawn ssh user @ host命令> outfile)

[英]bash command redirection in expect script failing with permission denied (spawn ssh user@host command > outfile)

我有這個expect腳本

#!/usr/bin/expect -f
set pass [ exec echo my_phrase | gpg --batch --quiet --yes --passphrase-fd 0 -d /root/.password-store/ssh/my_pgp_store.gpg ]
spawn ssh -oStrictHostKeyChecking=no -oCheckHostIP=no -i /home/myuser/.ssh/id_rsa ssh-user@remote-host.com /some/remote/script > /home/myuser/ssh.output
expect "*?assword:*"
send -- "$pass\r"
interact

那應該讀取一個gpg加密的密碼,並使用它通過ssh調用遠程腳本(有很多原因使我需要這樣做)。 現在,我的問題是,每當我運行此腳本時,ssh連接都已正確建立,但在寫入ssh調用的輸出ssh失敗,並顯示錯誤

bash: /home/myuser/ssh.output: Permission denied

我以root用戶身份運行腳本(因為必須以root用戶身份運行),並且我已經嘗試更改所有涉及的文件和目錄的權限和所有權。

redir char >對於Expect的spawn命令不是特殊的。 命令

spawn ssh user@host command > outfile

的意思與

spawn ssh user@host "command > outfile"

並且redir > outfile將在遠程主機上執行。

嘗試這樣:

spawn bash -c "ssh user@host command > outfile"
expect "assword:"
send -- "$pass\r"
interact

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM