shell script for ssh
source link: https://www.codesd.com/item/shell-script-for-ssh.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
shell script for ssh
Could anyone plese help me for creating a shell script. my script is something like this. I am a very beginner in shell scripting.
!/bin/bash
ssh user@server
mkdir test
"Actually what I was trying to do is, login to my server, and logout from there after creating a directory in server, by running a shell script in my local machine.But after the execution of the first command it will ask for the password for SSH and login to the server.The remaining code will not execute in server.when I exit from the server by typing CTRL+D, the remianing code will execute in my local machine.What should i need to do for executing the
remaining code in server and exit from the server automatically."
You have to put the command to be executed on the remote server on the same line as the ssh
call. E.g.:
ssh user@server "mkdir test"
If you want to run multiple commands, separate them with a semi colon. E.g.:
ssh user@server "cd /tmp/ ; mkdir test ; echo 'Done'"
Or you could just copy a script and then kick that off. E.g.:
scp remote.sh user@server:/tmp/remote.sh
ssh user@server "/tmp/remote.sh"
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK