How to run client script on on remote host and get results to the client

8,826

Like this:

ssh host sh -s < script.sh

To redirect remote output to local file:

ssh host sh -s < script.sh > output.txt

Explanation:

ssh host sh will invoke to default shell on the remote host. The -s option will tell the remote shell to read commands from standard input. Lastly the redirection < script.sh will attach stdin of the remote shell to the local file script.sh. The last redirection in the second example > output.txt will attach the stdout of the remote shell to the local file output.txt.

Share:
8,826

Related videos on Youtube

Ram
Author by

Ram

Updated on September 18, 2022

Comments

  • Ram
    Ram almost 2 years

    How to run script residing on the client on a remote host and get results back to the client in one go.

  • Thomas Nyman
    Thomas Nyman almost 11 years
    That requires script.sh to reside on the remote host.
  • Ram
    Ram almost 11 years
    The below script I have written to check the status of the listener of a database. I have this file on my client (windows machine running cygwin). I request your help in knowing how to execute this client script on the host and create a log on the host and ship the log back to the windows machine running cygwin (client). ################## #### chk_lsnr.sh ################### rm -f lsnr.exist ps -ef | grep LISTENER | grep -v grep > lsnr.exist if [ -s lsnr.exist ] then echo "Listener is up and running" > lsnr.log else echo "Alert LISTENER DOWN " > lsnr.log fi rm -f lsnr.exist
  • Ram
    Ram almost 11 years
    Thomas, Your suggestion worked like a charm!!!! I really Thank You for all the help.