0

So, I am trying to create an ask system there one computer (,lets call it computer nr1,) asks another computer (computer nr2) a question. The answer will be replied through a textdocument in the computer nr1. The question nr1 can be asking doesn't really matter atm, but let say nr1 ask when nr2 last rebooted.

I am using ssh to ask the question but it doesn't work. I'm sshing nr1 to nr2 and then, for example, asking when it last rebooted by:

who -b | awk '{print $(NF-1)" "$NF}' >> existing_file_in_nr1.txt

But when I run the command it places the answer in computer nr2. What do I do if i want my reply to go to computer nr1 instead of computer nr2 when sshed from nr1 to nr2?

Thanks.

2 Answers 2

3

Run the question over SSH but capture the answer outside SSH.

On nr1:

ssh user@nr2 'who -b' | awk '{print $(NF-1)" "$NF}' >> existing_file_in_nr1.txt

0
2

Instead of SSHing and the running the command on the shell started by SSH, use SSH to run the command directly. Then the redirection will happen on the local system. From nr1:

ssh nr2 who -b | awk '{print $(NF-1)" "$NF}' >> existing_file_in_nr1.txt

In this case, only who -b is run on nr2. Everything else happens on nr1.

While already on nr2, there's not much you can do to affect nr1. You can SSH back to nr1, or something similar, but that's about it.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .