How to nohup a command containing a pipe

330 views
Skip to first unread message

Yong Huang

unread,
Jul 25, 2002, 7:01:40 PM7/25/02
to
On Solaris, how do I make this command immune from SIGHUP:

sleep 60 | awk '{print 1}'

(Don't consider why I sleep and pipe. The point here is pipe)

I put nohup in front of it but SIGHUP disposition is still default
(checked with /usr/proc/bin/psig on Solaris) and indeed closing the
terminal window kills the process. Tried enclosing that line with ""
or (). Got syntax error. Thanks for help.

Yong Huang

Søren Hansen

unread,
Jul 26, 2002, 4:48:23 AM7/26/02
to
On Thu, 25 Jul 2002 18:01:40 +0200, Yong Huang wrote:
> sleep 60 | awk '{print 1}'

There's always this:

nohup $SHELL << EOF


sleep 60 | awk '{print 1}'

EOF


--
Søren Hansen Linuxkonsulent I/S
Open source specialist http://www.linuxkonsulent.dk
s...@linuxkonsulent.dk

Yong Huang

unread,
Jul 26, 2002, 11:27:38 AM7/26/02
to
Søren Hansen <s...@linuxkonsulent.dk> wrote in message news:<pan.2002.07.26.08....@linuxkonsulent.dk>...

> On Thu, 25 Jul 2002 18:01:40 +0200, Yong Huang wrote:
> > sleep 60 | awk '{print 1}'
>
> There's always this:
>
> nohup $SHELL << EOF
> sleep 60 | awk '{print 1}'
> EOF

Thanks. I appened & to your second line and that works.

I thought my real work could be replaced by that sleep 60 | awk line.
I was wrong. What I really want is this:

tail -f httpds_access_log | nawk '{if($0~/Some Error/) system("echo
Check Apache | mailx -s CheckApache yon...@yahoo.com")}' &

[It's one line; nawk doesn't allow line break] This checks new lines
appended to Apache access log and emails me when "Some Error" is
found. It runs fine like this. But it doesn't email me when it's
wrapped between nohup $SHELL <<EOF and EOF. Any idea?

Yong Huang

Yong Huang

unread,
Jul 29, 2002, 4:59:06 PM7/29/02
to
yon...@yahoo.com (Yong Huang) wrote in message news:<b3cb12d6.02072...@posting.google.com>...

> tail -f httpds_access_log | nawk '{if($0~/Some Error/) system("echo
> Check Apache | mailx -s CheckApache yon...@yahoo.com")}' &
>
> [It's one line; nawk doesn't allow line break] This checks new lines
> appended to Apache access log and emails me when "Some Error" is
> found. It runs fine like this. But it doesn't email me when it's
> wrapped between nohup $SHELL <<EOF and EOF. Any idea?
>
> Yong Huang

I guess there's no better way. So I put that tail -f | nawk line in a
script and nohup thatscript. It works. I wish nohup was rewritten to
support command sequences.

Yong Huang

Michael Wang

unread,
Jul 30, 2002, 1:33:48 AM7/30/02
to
In article <b3cb12d6.0207...@posting.google.com>,

Yong Huang <yon...@yahoo.com> wrote:
>I guess there's no better way. So I put that tail -f | nawk line in a
>script and nohup thatscript. It works. I wish nohup was rewritten to
>support command sequences.

nohup is rewritten, and it is called "submit".

"submit" can do all nohup can do, plus something that nohup can not do.
For example, you can use "submit" to do what you want to do:

submit "command1 | command2"

Unfortunately it is not a native command, but you can get it from
URL below and put it in your PATH. [Posted and Emailed].
--
Michael Wang
http://www.unixlabplus.com/

Yong Huang

unread,
Jul 30, 2002, 11:39:13 AM7/30/02
to
mw...@mindspring.com (Michael Wang) wrote in message news:<0zp19.570$yf2.1...@news.uswest.net>...

Thanks, Michael. That's pretty impressive. It'll be very useful if the
submitted job needs some sophisticated control.

BTW, I find that nohup somecommand | nohup othercommands also works
for me. So I'm doing this now:

nohup tail -f access_log | nohup nawk '/SomeString/ {system("mailx -s
ChkIt yon...@yahoo.com < /dev/null")}' &

In order to suppress "Sending output to nohup.out", I run it in csh.

Yong Huang

those who know me have no need of my name

unread,
Jul 30, 2002, 2:15:42 PM7/30/02
to
in comp.unix.shell i read:

>BTW, I find that nohup somecommand | nohup othercommands also works

perhaps you want:

nohup sh -c "command1 | command2"

--
bringing you boring signatures for 17 years

Reply all
Reply to author
Forward
0 new messages