Automate the operation started from ssh login
I would like to automate the CLI operation started from ssh login.
This may be a useful if you would like to repeat the similar command.
This can be come true with sshpass. Here is a sample.
for i in `seq 1 10`;do (echo "somecommand 1";echo "somecommand 2";echo "specific_command $i";echo "exit") | sshpass -p $pass ssh $sshuser@$ssh_target_host;done
This example is same as the following steps.
- ssh $sshuser@$ssh_target_host
- Type $pass as $sshuser password
- execute somecommand 1
- execute somecommand 2
- execute specific_command 1
- logout by exit
- ssh $sshuser@$ssh_target_host
- Type $pass as $sshuser password
- execute somecommand 1
- execute somecommand 2
- execute specific_command 2
- logout by exit
- repeat from ssh $sshuser@$ssh_target_host to logout by exit until repeat count will reach 10
Specific_command requires any argument which is not static value. This is useful against the case like defining multiple IP address from remote host.