I want to run multiple commands automatically like sudo bash, ssh server01, ls , cd /tmp etc at server login.. I am using Remote command option under SSH in putty.
I tried multiple commands with delimiter && but not working.
I want to run multiple commands automatically like sudo bash, ssh server01, ls , cd /tmp etc at server login.. I am using Remote command option under SSH in putty.
I tried multiple commands with delimiter && but not working.
You can execute two consecutive commands in PuTTY using a regular shell syntax. E.g. using ;
or &&
.
But you want to execute ssh server01
in sudo bash
shell, right?
These are not two consecutive commands, it's ssh server01
command executed within sudo bash
.
So you have to use a sudo
command-line syntax to execute the ssh server01
, like
sudo bash ssh server01
I tried what I suggested in my previous answer.
It is possible to run 2 simple commands in putty separated by a semicolon. As in my example I tried with ls and echo. The remote server runs them and then the session closes.
I also tried to ssh to a remote server that is configured for not asking for a password. In that case, it also works, I get connected to the 2nd server and I can run commands on it. Upon exit, the 2 connections are closed.
So please, let us know what you actually need / want.
There is a some information lacking in your question.
You say you want to run
sudo bash
, thenssh server01
.Will sudo prompt for a password in your remote server?
Assuming there is no password in sudo, running bash will open another shell waiting for user input. The command
ssh server01
will not be run until that bash shell is exited.If you want to run 2 commands, try first simpler ones like:
or if you prefer:
Does this work?
If what you want is to run ssh after running bash, you can try :