Re: Thanks and Suggestions



On Sun, Mar 1, 2009 at 7:09 PM, Chris Mirchandani <novashadow@xxxxxxx> wrote:

Thank you Mr. Lanning,

I tried your suggestion, see below, and it does work like I want, but I have 2 questions.

ssh joe@xxxxxxxxxxx "sleep 1000 < /dev/null> /dev/null 2>&1 &"

1) I see a lot of scripts use the form /dev/null> /dev/null 2>&1 rather than < /dev/null
> /dev/null 2>&1. Why don't you want/need the latter in scripts?

This actually depends on the command running.

< /dev/null
This redirects STDIN (usually the keyboard) to read from /dev/null.
/dev/null is a special
file (called a device file) that gives the End Of File marker every
time it is read. If you
want the command to read from a file, then you replace "/dev/null"
with /path/to/file.
/dev/null
This redirects STDOUT (usually the screen) to /dev/null. Anything
written to /dev/null
is just discarded. So, if you want to save the output to a file,
then you replace "/dev/null"
with /path/to/output/file. You do have to be careful, as the ">"
operator truncates the file
when it opens it for writing.
x>&y
This copies file descriptors.
STDIN is file descriptor 0
STDOUT is file descriptor 1
STDERR is file descriptor 2
So, 2>&1 copies file descriptor 1 to file descriptor 2, thus makes
STDERR goto the same
place as STDOUT.
If you want STDERR to goto a different file than STDOUT, then you can use
"2> /path/to/error/file"

If you don't use "< /dev/null" then the command will still have the
terminal open for reading.
Sometimes this is just fine, as the command does not do anything with
the terminal (ie. read
from it.) Sometimes it isn't, if the command tries to read from
STDIN, it will interrupt your
shell.

If you want to close your shell completely, then you will need to
redirect STDIN for
the command, as the terminal will disappear (if it is a network or
Xwindow session.) In this
case, you will also want to use "nohup" to run the command. This will
set the process flag
to ignore the HangUp (SIGHUP) signal, that the shell sends to all it's
child processes upon
exit. Commands that do not specifically handle SIGHUP will default to
exiting upon
receiving the HUP signal.

In Linux, you can get a list of all available POSIX Signals via the
"kill -l" command or
looking in /usr/include/linux/signal.h.

2) If I enable logging for my remote ssh command, which is an ssh command, will
< /dev/null> /dev/null 2>&1 change logging in any way?

This all depends on how logging is implemented.

If it uses Syslog or writes directly to a file, no. If it logs to
STDOUT or STDERR, then yes.

See above for what happens to STDOUT and STDERR, if logging is done
via either of
those.

If it uses Syslog or writes directly to a file, then the log will be
on the remote machine,
only.

--
And, did Galoka think the Ulus were too ugly to save?
-Centauri



Relevant Pages

  • Re: STDOUT and STDERR redirection fails for forked process
    ... Simply, fork a command using the OPEN instruction, ... redirect STDERR to STDOUT and capture the returncode of the executed ... and the returncode is not captured. ...
    (comp.lang.perl.misc)
  • Re: getting stdout and stderr for system calls on windows
    ... It doesn't separate stderr and stdout, but for what I want it, it's more than enough. ... #You can then access the output and the return value for the command. ... def initialize cmd ...
    (comp.lang.ruby)
  • Re: How can i let shell program within TCL show run log?
    ... You'll find there that>@ means "redirect child's stdout to a Tcl ... and 2>@ the same for child's stderr. ... could be directly ran to display a command output on a text widget (a ...
    (comp.lang.tcl)
  • Re: Copying silently.
    ... so as to ReDirect both StdIn & StdErr for a Command, ... to think that "I've done it" is fit for stdout, ... do it" is fit for stderr. ... for reports on both Failure & Success? ...
    (uk.people.silversurfers)
  • Re: Getting both PID and output from a command
    ... > I'm calling a command from within a python script and I need to be ... > able to both catch the output (stdout and stderr) from it and also ... > I've tried doing the following to grab stderr (I only need stderr, ... I wouldn't trust using a pipe. ...
    (comp.lang.python)