I am executing a script through ssh like this:
ssh $USER@somehost 'bash -s' < ./myscript.sh
sudo -i -u svcacct # use the service account
exit # last working command
A working implementation, emitting
3, would look like:
echo '1' sudo -u svcacct -i bash -s <<'EOF-1' echo '2' EOF-1 echo '3' exit echo '4'
Note that we're not depending on any program to exit leaving the file descriptor for stdin with any particular content queued-up to be read, but instead are providing the
svcacct instance with only a very limited and specific subset of stdin from a distinct heredoc.