Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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
add comment

1 Answer 1

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
    command1; 
    command2;
    command3;
    command4;
    command5;
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 at 6:15
    
I've updated my answer to include this use case. –  Sylvain Pineau Mar 28 at 10:33
add comment

Your Answer

 
discard

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.