i have seen similar questions on the web but none of the answers work, hoping a fresh request will reveal an answer.
i am trying to run a remote query on a linux box which i can do the problem is i stay connected to the remote server.
i have set -x in the script so i am watching the output. Part of my script is below
ssh -tt $host.digital.domain.com << EOF
sudo su - foo
/apps/scripts/bar.sh
exit
EOF
the script is runs correctly
[user@server ~]$ [foo@host ~]$ + rm -f '/tmp/files*'
however the window then gives me the prompt on the remote computer instead of exiting.
[foo@host ~]$
i used the -tt switch as i was getting the tty error i have also tried to kill the pid but this doesnt work either. the only way to progress the script is for me to 'ctrl c' to exit the remote session.
i have tried running ssh it all on one line however this didnt work, possibly due to the sudo, i'm not sure.
Any advice would be great.
thanks
With the "su" command you open new bash session. If you only write one "exit", you only finish the session of foo user. For finished the session open by the ssh connection you should write other "exit".
ssh -tt $host.digital.domain.com << EOF
sudo su - foo
/apps/scripts/bar.sh
exit #Exit foo session
exit #Exit ssh session
EOF
Output:
sshuser@prompt$ sudo su - foo
foo@prompt$ /apps/scripts/bar.sh
foo@prompt$ exit #Exit foo session
exit
sshuser@prompt$ exit #Exit ssh session
logout
Connection to $host.digital.domain.com closed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With