I'm trying to automate a server update process. What this should do is check for git diff files and list them, to later be copied from one place to the other.

Here's my script on my local machine:


ssh [login details] -t -t 'bash -s' < ~/Scripts/update_frontend_cmd.sh



cd "$SOURCE"
for i in $(git diff --name-only origin/master master)
    x=`echo $i | sed 's/mydir\///'`
        dothis=`echo "
cp './mydir/$x' '$TARGET/$x'"`

git pull
eval $dothis

Problem is, after any first input from me (be it login for git pull, or if I remove it, any other command I try to execute) causes the shell to hang. I just get a blank line an infinite waiting. Any idea what's causing this?

  • 2
    For starters, add set -x to the top of your script to trace its execution and to see where it stops.You shouldn't use single quotes around variables like $x because then they will be literally expanded to $x not the value of x.
    – user13742
    Jun 10, 2013 at 15:02
  • The script runs entirely - when it's done I'm thrown to the shell, and then any input causes a hang. Entering the shell manually with ssh doesn't cause the hang. As for the single quotes, notice it's part of a multiline string that starts a bit higher, which is in double quotes. The string output is fine when I test it.
    – casraf
    Jun 10, 2013 at 15:05
  • What exactly do you mean by "any first input from me"? Jun 10, 2013 at 16:14
  • I mean as a shell would expect keyboard input, I input any command and as soon as I hit enter that's it. But it doesn't execute.
    – casraf
    Jun 11, 2013 at 7:09

3 Answers 3


After your update_frontend_cmd.sh has been processed, you are at the end of the input. ssh does not simple switch back to keyboard input from that.

What you could consider is running a screen session on the remote machine and execute commands in there. Then reconnect once you are done.

A more simple possibility is pushing the script to the server (scp, or better pushing via git) and executing it locally.

  • Ended up copying the script to the remote machine.
    – casraf
    Jun 11, 2013 at 7:17

Just omit the -t options from ssh invocation, and the session will terminate once EOF is reached on stdin.

  • But then I couldn't pass the script properly, I've tried before.
    – casraf
    Jun 11, 2013 at 13:30

This works for me:

( echo 'echo yes'; echo 'exit') | ssh me@localhost -t -t 'bash -s'

Try replacing the echo 'echo yes' with your cat.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.