ENJOY THE SILENCE
Marigan's Weblog
All | General | Java | Music | NetBeans | Unix
« The Tao Of Programmi... | Main | How the vi editor... »
20050814 Sunday August 14, 2005
Executing scripts on a remote machine
These are a few quick tips how to make it real. First what you need: two computers ;), both to have bash and ssh installed and 'authorized_keys' file with public rsa key from the caller machine (only if you want to have communication without password typing)

Now let's do it :

1. Make a simple bash script which we want to execute on a remote machine. You are able to use this one:
#!/bin/bash
echo "Greetings from "$(uname -n)
exit 0
2. Execute this script on a remote machine by running this:
cat simple.sh | ssh user@remote /bin/bash
You should see this output:
Greetings from remote
It's unbelievably simple isn't it ? You send content of the script file through the pipe to a remote machine on which you connect via ssh and where you run the bash in which you execute the script that come from your computer .;) Due to these nice features i do really love unix :)

Aug 14 2005, 09:29:17 PM CEST Permalink Comments [5]

Trackback URL: http://blogs.sun.com/marigan/entry/executing_scripts_on_a_remote
Comments:

I have executed the following script using this method #!/bin/bash touch remote.txt ls -l > remote.txt exit 0 But it is creating remote.txt? or remote.txt^M file instead of remote.txt Seems to be there is newline character problem, but how to avoid it.

Posted by sathish on September 13, 2005 at 01:27 PM CEST #

Following command working fine for me. ssh schalla@rcdevserver /bin/csh < test.sh

Posted by sathish on September 13, 2005 at 01:46 PM CEST #

hi, i want to ask suppose we have to give some arguement to simple1.sh script then what will be the command to run it a remote machine >?? please help.

Posted by nicky on October 26, 2005 at 08:50 AM CEST #

you can call more commands on remote machine by this: cat simple.sh | ssh user@remote `export TEST=test`;export TEST2=test2`;/bin/bash simply divide commands by ; (semicolon)

Posted by marigan on January 16, 2006 at 11:56 PM CET #

Thanks a lot, you saved my life :-)

Posted by Mohannad Hussain on June 21, 2007 at 04:33 PM CEST #

Post a Comment:

Name:
E-Mail:
URL:

Your Comment:

HTML Syntax: NOT allowed