Find the answer to your Linux question:
Results 1 to 3 of 3
I need to output of the script to the remote server via redirect. I created a simple script for your reference. #!/bin/bash W=`/usr/bin/w` FREE=`/usr/bin/free` echo "$W $FREE" I need the ...
  1. #1
    Linux Newbie
    Join Date
    Mar 2006
    Posts
    101

    redirect output to remote server via ssh

    I need to output of the script to the remote server via redirect. I created a simple script for your reference.

    #!/bin/bash

    W=`/usr/bin/w`
    FREE=`/usr/bin/free`


    echo "$W

    $FREE"
    I need the output of the script to be transferred to the remote server (192.168.0.1) and do it via ssh or scp. I tried the following:

    ssh -i /home/foo/test root@192.168.0.1 "/path/scrpt.sh"
    I got error when I tried the command above.

    Any recommendation.

    TIA

  2. #2
    Just Joined!
    Join Date
    May 2009
    Posts
    4
    Hi,

    what you do is this.
    1. you use scp

    scp /path/script.sh root@192.168.0.1:foo/test/

    This will copy the script to the directory /root/foo/test on the remote server, if that's your objective.

    If you want the output of that script to be sent, depending on what the script does, you can do something like this

    `scp $output root@192.168.0.1:foo/test/

    where $output is what is produced from the script.
    Before that generate a pair of keys, store the public one on the remote machine so that you are not asked for password.

  3. #3
    Linux Newbie
    Join Date
    Mar 2009
    Posts
    228
    The command you posted tries to run the script on the remote host. If you want to direct the output to the remote host when you execute the script on the local host the command would look something like:

    Code:
    /path/script.sh  2>&1 | ssh root@192.168.0.1 "cat > /path/script.log"
    I left out the ssh -i option so it'll prompt you for the password. Try getting this to work first and then add the use of public/private keys.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...