Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!samsung!olivea!bu.edu!mirror!kiyun From: kiyun@mirror.tmc.com (KiYun Roe) Newsgroups: comp.unix.shell Subject: Getting HUPed Message-ID: <53767@mirror.tmc.com> Date: 20 Mar 91 15:16:41 GMT Distribution: na Organization: Mirror Systems, Cambridge Ma. Lines: 36 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@mirror.TMC.COM Mirror Systems 2067 Massachusetts Avenue Cambridge, MA 02140 Telephone: 617-661-0777