Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have two ubuntu systems one server and another is client.

So I have written one script on server, following are the code of script file:

Code for login into the client system

`sshpass -p prakash12 ssh -p 11111 prakash@localhost` 

This command must have to fire on logged on client system.

${HOME}/temp/.git describe --always --tags HEAD

The first command executed successfully for logged on to the client system.But second command is get fired on server system insted fired on logged on system.

So how can I fired the second command on the client system from the server.

share|improve this question
up vote 1 down vote accepted

You can send command remotely, simply provide the command in quotes following the ssh log-in command, like this:

sshpass -p prakash12 ssh -t -p 11111 prakash@localhost '${HOME}/temp/.git describe --always --tags HEAD'

If you need to pass more command over ssh you have several options:

Use semicolon to separate the commands:

ssh -t -p 11111 prakash@localhost 'command1 ; command2 ; command3'

Use a here document:

ssh -t -p 11111 prakash@localhost << EOF
share|improve this answer
Your ans is working but after execution of 2nd command the connection to client system is closed. Means 1st command also lost the session. But I want to execute the 4/5 more commands after the 1st command i.e. login command is executed. – Prakash V Holkar Mar 28 '14 at 6:15
I've updated my answer to include this use case. – Sylvain Pineau Mar 28 '14 at 10:33

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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