Getting HUPed

KiYun Roe kiyun at mirror.tmc.com
Thu Mar 21 01:16:41 AEST 1991


I've been encountering a problem with some of my shell scripts and
SIGHUP that I don't understand.  I run a lot of scripts overnight.
These are usually named xsomething.sh.  They may generate temporary
files which I want to clean up.  Here's what I want to use to start
them off:

    #! /bin/sh

    type=`expr $0 : '.*x\(.*\)\.sh'`
    exec > x$type.log 2>&1

    trap "rm -f /tmp/p$$.* ; exit" 0 1 2 13 15

This automatically redirects stdout and stderr to a log file and cleans
up some temp files on exit or certain signals.

The problem is that I log back in the next day and find out that the
script has long finished its real work, but it's forking like crazy,
trying to do the rm.  I guess each time it tries to do the rm it
receives a SIGHUP which forks another subshell to do the rm.

I don't understand this.  First, I thought that the -f flag would keep
rm quiet, so I don't understand why it has to interact with the
terminal at all.  Second, I thought the exec > .. 2>&1 would redirect
all output, but it doesn't.  If I do "xsomething.sh >& save.out &"
before I log out (I use tcsh), when I log back in save.out contains a
Hangup message for each subshell and xsomething.log (the automatic log
file) doesn't contain anything.  Finally, most of the times there are
temporary files to cleanup, so the globbing and rm should work
normally.  I can't figure out whether this is a bug in our version of
sh or whether things are "supposed" to work this way.

----
KiYun Roe	kiyun at mirror.TMC.COM
Mirror Systems	2067 Massachusetts Avenue  Cambridge, MA  02140
Telephone:	617-661-0777



More information about the Comp.unix.shell mailing list