Re: Thanks and Suggestions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

[Index of Archives]     [Open SSH Unix Development]     [Fedora Users]     [Fedora Desktop]     [Yosemite Backpacking]     [KDE Users]     [Gnome Users]

  Powered by Linux