Is there any way I can combine the following commands into one command? I do not want to login in each time for each command.
sshpass -p 'somepwd' ssh user@server "mkdir -p /home/user/test"
sshpass -p 'somepwd' scp file.sh user@server:/home/user/test
sshpass -p 'somepwd' scp /test/somefile.txt user@server:/home/user/test
sshpass -p 'somepwd' ssh user@server -C "cd /home/user/test;./file.sh"
I did check the answer for combing multiple commands when using ssh and scp; Based on that I would still need 3 logins, one for first ssh and mkdir, one for scp and one for ssh and running the shell script.
Is there a better solution?
ssh? If not, try searchingssh-keygenor do aman ssh-keygen.rsyncto copy multiple files, and it will automatically create directories as needed. So that allows you to combine the first 3 commands.ControlMasteris your friend -- you can have a single connection used for multiple commands.