0

Is it possible, when locally writing output from SSH command execution, to suppress the hostname and [sudo] lines?

For instance, when I SSH into a server and run sudo <command> it displays

<hostname>
[sudo] password for user:

This is written to the file I'm writing the output to. I'm using sudo <command> 2>&1 /dev/null but it isn't eliminating those lines.

0

sudo <command> 2>&1 /dev/null won't redirect anything to /dev/null. Instead, you are:

  • Calling sudo with 2 parameters: <command> and /dev/null. The second one will be passed to <command> when it gets executed.
  • Redirecting error messages to standard output.

Here's a simple try:

$ sudo ls 2>&1 /dev/null
/dev/null

See: you get the result of ls /dev/null. However, you could do something like...

$ sudo ls >ls_output.txt 2>/dev/null

Which would:

  • Call sudo with 1 parameter: ls.
  • Redirect standard output to ls_output.txt.
  • Redirect standard error to /dev/null.

With the above command, ls_output.txt would list the contents of the current working directory, and won't have any stderr data in it.

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.