How to use ssh and run command in the remote machine using shell script
Hi All,
As mentioned in the Subject ...How can i do that.. Today is my first day writing a script.. and correct me if this Thread should be somewhere else..I rarely use this forum. Code:
if [ $1=$anyvariable ]; then |
Hello,
SSH gives you the possibility to execute commands from the command line like this: Code:
ssh user@server 'your command; other command; next command' Code:
ssh user@server <<<EOF Some examples and tips: Right here at LQ Using SSH from Bash http://tldp.org/LDP/abs/html/communications.html#REMOTE Kind regards, Eric |
Thanks EricTRA but this doesnt answer my question.
You mentioned how in the terminal ssh can be done.. but what i wanted to ask is how in script you can give some command (like setenv or ls -a)intended for the remote pc after connecting to the remote terminal through ssh.. i tried ls -a in the below mentioned manner but it printed out the content of my local folder...whereas, i anticipated it show the contents of the current remote folder.. Code:
if [ $1=$anyvariable ]; then |
Hello,
There is basically not that much difference between executing SSH commands from the console or from within a shell script. I don't think you've read through the links I posted since all of them contain examples on how to put SSH with remote commands in a script. Also have a second look at the console examples I posted, both of them mention Code:
ssh user@host 'command' Code:
ssh www.a.com 'command' For example, if you would like to put the following you execute from a terminal in a Bash script: Code:
ssh user@host 'ls -l' Code:
#!/bin/bash Code:
chmod +x sshtest.sh Code:
./sshtest.sh Kind regards, Eric |
Thanks EricTRA,
Quote:
ssh emulator 'ls -a' it connects to the emulator and disconnects it after showing me the contents of the directory.. I dont want it to be disconnected.. Quote:
Quote:
also what would be the command to see where the host name is pointing too ? Quote:
|
Quote:
Quote:
Quote:
Quote:
Kind regards, Eric |
Quote:
Quote:
Quote:
first i want to ssh ..then set some environment variables and paths in the remote machine and then i want to issue few ssh connection originating from the remote prompt without disconnecting these connections until ctrl+c ... :) i will explain how i am doing it in the terminal now so its more clear Code:
[local/home/blabla]ssh connection |
you can do that normally with one ssh command
Code:
ssh user@host 'command1; command2; command3; ...' After all the commands are done, then he disconnects NORMALLY :p EDIT you can also do this in a script script.sh Code:
ssh user@host 'command1; command2; command3; ...' Code:
# chmod 755 script.sh Code:
# ./script.sh |
Thanks brownie but this doesnt help...Please read my post before your http://www.linuxquestions.org/questi...5/#post4339110
|
All times are GMT -5. The time now is 10:02 AM. |