0

I am sshing into a remote machine and running a command there using sudo. I am using tt for TTY connection. I want to get the output (the console logs) of the command that I am running in my local machine. How can I do that?

ssh -i keyfile -tt user_name@$web_ip "sudo p.sh"

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
  • I think this needs clarification. Is the output of the command that you are running on the local machine crucial to enable your command to run on the remote machine? Could you just copy the relevant file to the remote machine (using scp) before running your command over ssh? – SauceCode Nov 29 '16 at 03:52
  • I am running ssh -i keyfile -tt user_name@$web_ip "sudo p.sh" in my local machine. p.sh is getting executed on the remote. I want to direct the logs of p.sh in my local machine. – user2851669 Nov 29 '16 at 03:57

1 Answers1

0
ssh -i keyfile user_name@$web_ip "sudo p.sh" > p.sh.local.log

I think this will do what you want, at least if p.sh is a pretty simple script (like ls -al). (Note removing -tt)

For realtime logs:

ssh -t -i keyfile user_name@$web_ip "yes" > yes.local.log

Note: the yes command produces lots of output so this will make a large file fast. But it does update in realtime, in my test.

SauceCode
  • 2,345