0

I want to create a .command-script on Mac, to execute a series of commands on a remote server using SSH. My script looks something like this:

ssh user@domain.com
cd /var/www/website/
git pull

However, I need to enter my password after the first command (to actually gain access to the remote server). The rest of the script does not get executed after entering my password.

How can I tell the terminal to execute the following commands after I entered my password?

NB: I don't want to put my password in the .command-file.

1

In this solution we need to tell ssh to create a pseudo terminal with -tt then use a heredoc to send the commands to the remote location.

    ssh -tt user@domain.com <<EOF
    cd /var/www/website/
    git pull
    logout
    EOF 
  • Thanks so far! That works. However my situation is a little more complex than I initially wrote down. I actually have to go from Client to Server A, then to Server B, then do the pull. I've had no luck nesting those heredoc notations. Is there any way to do the same trick within the first remote server? – Sherlock Jul 24 '15 at 12:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .