Send output of command to a different server
How can I perform the following in one command? If not one, what about two?
Code:
# Currently logged on server 999.999.999.999 |
Try something like
command 1234 | ssh user@remote_host "cat >> file_name" |
Thanks nodir,
So, run command 1234,pipe it to sshing into remote host, and cat'ing the results to file_name? Why >> instead of >? Also,what if I was currently logged on remote_host? |
i copied the command from a script where i want to append to a textfile.
Hence the >> instead of a > (in short: a typo. sorry :-). And yes, i guess you gave the general summary of it (the quotes around " cat > filename" do matter, if i recall correct). ssh command only executes the command remote, after that you are still local (in case that was a question) Not sure about the other question, user is logged in remote, i guess it doesn't matter. good luck. |
> as apposed to >>
> writes to the file if something is already there is gets written over will the new stuff. >> appends whatever is being sent to what is already there. using >> on first write will still get a file written, just the next time you will not have to change the > to >> if you are keeping a log type file, it saves recoding. Using nodir example with a little change to path to directory first. Code:
command 1234 | ssh user@remote_host "cat >> /path/to/dir/file_name" |
that would work, the question I have is, do you have root access to these machines? If so could you use an NFS share? or fuse SSHFS to mount the remote directory locally and then just read/write the file/directory as if it were local? Just a thought.
|
rsync would be better, it already has the ability to handle this with the --remove-source-files flag
thinking something like Code:
/path/to/command 1234 > /path/to/file && rsync -avz --remove-source-files /path/to/file user@host:/destination/path |
All times are GMT -5. The time now is 10:44 PM. |