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

Re: redirect hidden output to screen...?

> I have a li'l program I wrote, Mail-Penguin, that retrieves mail for us
> from our POP box on the web -- it's a home-brewed 'fetchmail', sort of.
> Normally it sends informational messages to the screen -- but now I
> have it being launched by diald's ip-up script (which I guess is
> sending output to its FIFO...?)
> How can I restore or mirror that output to the console screen...?
this is a small script, which makes a "parent follow up" to find the
console, on which it is probably running (even if i/o is redirected):

w=`who|cut -c10-18|echo $(</dev/stdin)`; tty=; n=$$
while test "$n" != 1; do
  p=`ls -l /proc/$n/fd/0`; p=${p##*-> }; pt=${p#/dev/}
  test "$p" != "$pt" -a "$w" != "${w##*$pt}" && { tty=$p; break; }
  n=`awk '/^PPid:/ {print $2}' /proc/$n/status`

$tty is now empty (if no console could be found) or it contains someting
line "/dev/tty1" or "/dev/pts/1" etc.
if you think, it's not worth the effort (or my script just fails in your
case), then just use a fixed tty (e.g. tty10), but then you would have to
switch the virtual console.

if you want to redirect the output of the currently running script, then do

exec >$tty

or (to avoid an error message, if no console is found):

test $tty && exec >&$tty

if you want to duplicate the output of a program (maybe another script):

test $tty && program | tee $tty || program

i could not figure out, how to redirect the output of an already running
script to another program without creating a fifo ...

Hi! I'm a .signature virus! Copy me into your ~/.signature, please!
Linux - the last service pack you'll ever need.

Reply to: