I have this expect
script
JavaScript
x
#!/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 -- "$passr"
interact
that is supposed to read a gpg
encrypted password, and use it to call a remote script via ssh (there are many reasons why I need to do it like that). Now, my problem is that whenever I run this script, the ssh connection is correctly set up, but it fails in writing the output of the ssh
call with the error
JavaScript
bash: /home/myuser/ssh.output: Permission denied
I’m running the script as root (because I have to run it as root), and I already tried to change the permissions and ownerships of all the involved files and directories.
Advertisement
Answer
The redir char >
is not special for expect’s spawn
command. The command
JavaScript
spawn ssh user@host command > outfile
means the same as
JavaScript
spawn ssh user@host "command > outfile"
and the redir > outfile
will be executed on the remote host.
Try like this:
JavaScript
spawn bash -c "ssh user@host command > outfile"
expect "assword:"
send -- "$passr"
interact