0

I have a script which does ssh to all the servers and shows the output for each execution; can I redirect those outputs to /var/tmp/filename_output.txt on server1?

The script runs from server1 to all the server. These are the commands I'd like to execute to run the script and save the output:

ssh server1
./script.sh > /var/tmp/filename_output.txt

ssh server2
./script.sh >> server1:/var/tmp/filename_output.txt

ssh server3
./script.sh >> server1:/var/tmp/filename_output.txt
2

EDIT:

I have been doing some test if you run the command like this you will get local output

ssh yourserver < ./your_script.sh > your_script.stdout

END EDIT


From my point of view you have two options.

Option 1

After running script.sh on each server and been written the command output to /var/tmp/filename_output.txt on remote server

scp /var/tmp/filename_output.txt myserver:/prefered_location/server_name.log
rm /var/tmp/filename_output.txt

Option 2

Export a NFS from your server and importing on every server on your network, that way you can have a local FS on each of the other server pointing to the main one and your problems are solved by putting the command output on a file inside the FS pointing to the NFS.

If you need instruction on how to export a NFS and import it on client machines let me know

2
  • There isn't any other way to redirect the output to the remote host. – Mongrel Jan 29 '17 at 16:25
  • Checks my edit . I think that is the answer to your problem – Noel Carcases Jan 29 '17 at 16:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.