f



Can a script nohup itself?

Is it possible to have a script nohup itself in the Bourne shell? I
know there are work-arounds (multiple scripts being the most obvious)
but I'm curious if I can do this self-contained.

I believed (foolishly as it turns out) that I might be able to create
a function and then nohup my_function & to get the desired effect, but
it doesn't work that way since nohup only accepts commands or
programs, not functions, as a parameter. Anyone have a suggestion?
0
JustBob4Now
6/23/2004 8:59:29 PM
comp.unix.shell 15484 articles. 2 followers. Post Follow

6 Replies
3583 Views

Similar Articles

[PageSpeed] 42

JustBob4Now@hotmail.com wrote:
 > Is it possible to have a script nohup itself in the Bourne shell? I
 > know there are work-arounds (multiple scripts being the most obvious)
 > but I'm curious if I can do this self-contained.
 >
 > I believed (foolishly as it turns out) that I might be able to create
 > a function and then nohup my_function & to get the desired effect, but
 > it doesn't work that way since nohup only accepts commands or
 > programs, not functions, as a parameter. Anyone have a suggestion?

# Untested:
if [ -s /tmp/foo ]; then
   : Do useful stuff here
else
   echo $$ > /tmp/foo
   nohup $0 "$@" &
   wait
   rm /tmp/foo
fi

-- 
Kevin Rodgers

0
Kevin
6/23/2004 9:59:58 PM
JustBob4Now@hotmail.com wrote:

> Is it possible to have a script nohup itself in the Bourne shell? I
> know there are work-arounds (multiple scripts being the most obvious)
> but I'm curious if I can do this self-contained.
> 
> I believed (foolishly as it turns out) that I might be able to create
> a function and then nohup my_function & to get the desired effect, but
> it doesn't work that way since nohup only accepts commands or
> programs, not functions, as a parameter. Anyone have a suggestion?

Sure. 

I'm assuming you want to run your script with 'nohup' as a background job.
You can have your script recursively call itself with: 
        
        nohup "$0" "$@" &

However, make sure you have some *termination condition* that you check for,
else your script will recurse forever. For example, you might pass a
command-line parameter stating if your script was called by itself:
        
        #!/bin/bash

        if [ "$1" != "calling_myself" ]
        then
                # this script has *not* been called recursively by itself

                nohup "$0" "calling_myself" "$@" &
                exit
        else
                # this script has been called recursively by itself

                shift # remove the termination condition flag in $1
        fi

        # the rest of your script goes here

0
foo
6/23/2004 10:06:10 PM
JustBob4Now@hotmail.com wrote:
> Is it possible to have a script nohup itself in the Bourne shell? I
> know there are work-arounds (multiple scripts being the most obvious)
> but I'm curious if I can do this self-contained.

I'm not sure if other flavors of Unix alow this but Solaris 9 and better let you nohup 
pids and gpids.  

So you could do a nohup -p $$

It's so ellagent, you'd think they would have thought of this a long time ago.

--Brett
0
foo
6/24/2004 3:28:35 PM
2004-06-23, 15:59(-05), JustBob4Now@hotmail.com:
> Is it possible to have a script nohup itself in the Bourne shell? I
> know there are work-arounds (multiple scripts being the most obvious)
> but I'm curious if I can do this self-contained.
>
> I believed (foolishly as it turns out) that I might be able to create
> a function and then nohup my_function & to get the desired effect, but
> it doesn't work that way since nohup only accepts commands or
> programs, not functions, as a parameter. Anyone have a suggestion?
[...]

You can do:

#! /bin/sh
{
  trap '' HUP
  # the script
} &

-- 
Stephane
0
Stephane
6/24/2004 3:39:46 PM
2004-06-24, 15:39(+00), Stephane CHAZELAS:
[...]
> #! /bin/sh
> {
>   trap '' HUP
>   # the script
> } &

Actually:

#! /bin/sh
{
  trap '' HUP
  # the script
} > nohup.out 2>&1 &

would be closer to nohup behavior.

#! /bin/sh
{
  trap '' HUP
  # the script
} < /dev/null > nohup.out 2>&1 &

would even be better.

-- 
Stephane
0
Stephane
6/24/2004 3:48:41 PM
In article <1088090586.458586@news.zipcon.net>,  <foo@bar.com> wrote:
>I'm not sure if other flavors of Unix alow this but Solaris 9 and better
>let you nohup 
>pids and gpids.  
>
>So you could do a nohup -p $$
>
>It's so ellagent, you'd think they would have thought of this a long time ago.

The disown command has been in ksh93 a long time ago.
But I find it is of little use if you do not put the
process ($$ in your example) in background.
-- 
Michael Wang * http://www.unixlabplus.com/ * mwang@unixlabplus.com
0
mwang
7/17/2004 7:27:32 PM
Reply:

Similar Artilces:

can you translate shell script into perl script?
hi~~~ first of all if you wanna do this. you should make a directory called '.junk' in your home directory. and then please translate this into perl script. the teacher said this is so easy but I can't do this. but I'm trying to solve this. so would you help me. below is the script which must be translated into. ---------------------------------------------------------------------------------------------------- fileCount=0 listFlag=0 purgeFlag=0 fileFlag=0 junk=~/.junk for arg in $* do case $arg in "-p") purgeFlag=1 ;; "-l") listFlag=1 ...

How can I run php scripts from a shell script?
Newbie about this stuff. I want to run some php scripts from a shell script(bash?) the php script i want to run is this: test.php and it's path is this: home/virtual/blahblah.com/home/abc/mainwebsite_html/bluhbluh/dbtest/ 1. How would I creat the shell script? 2. How would I execute it? I have already tried ot figure it out with no success. I have php 4.2.2 Thanks john@munsey.net spilled the following: > Newbie about this stuff. > > I want to run some php scripts from a shell script(bash?) > > the php script i want to run is this: > test.php > > and it&...

web hosting, shell provider, unix shells, bnc shell, ircd provider, shell hosting, bnc shells, irc shells, ircd shells, unix shell account, irc shell, irc, eggdrop shell, irc vps, irc shell, linux vps
http://www.hostrazor.net/ web hosting, shell provider, unix shells, bnc shell, ircd provider, shell hosting, bnc shells, irc shells, ircd shells, unix shell account, irc shell, irc, eggdrop shell, irc vps, irc shell, linux vps -- questo articolo e` stato inviato via web dal servizio gratuito http://www.newsland.it/news segnala gli abusi ad abuse@newsland.it ...

can I run unix shell command in the ModelSim shell?
Hi, Just wonder if I can run unix shell command in the Modelsim shell, expecially those time/date command? Thanks. clinton__bill@hotmail.com wrote: > Hi, > Just wonder if I can run unix shell command in the Modelsim shell, > expecially those time/date command? ModelSim uses Tcl as its scripting language so (almost) anything you can do from Tcl can be done in ModelSim. Tcl has a variety of shell and file interaction commands available. Of course, if you want to execute Unix commands, you need to be running on a Unix (or Cygwin) system. Note that Tcl commands are NOT direct...

execute a shell script in a shell script
Please help. I have been stumbled on this issue, please see below. I am unable to execute a shell script in a shell script. I need to use perl script but not others and have tried eval, -exec and other on perl script but failed. system"cleartool setview -exec \"cleartool describe -fmt 'On %Sd modified %En and comment:\n %c\n\n' /myproject/vob/myprogram.C\" my_lag "; tks. On Dec 3, 8:30 am, moongeegee <moongee...@gmail.com> wrote: > Please help. > I have been stumbled on this issue, please see below. I am unable to > execute a shell script in a shel...

unix shell script
Hi all, I am in need of a shell script which will cat all the audit files into one log and then email. Thanks. Muddu "muddu" <mudassar.dba@gmail.com> wrote in message news:1156371761.252866.267670@b28g2000cwb.googlegroups.com... > Hi all, > > I am in need of a shell script which will cat all the audit files into > one log and then email. > "cat *.aud" will merge all files together. You can redirect it to a file and/or email. Thank you very much for your hint. Regards. Muddu Bob Jones wrote: > "muddu" <mudassar.dba@gmail.com&...

US-NJ-Jersey City: UNIX Developer, UNIX, Shell scripting, SwiftAlliance Access; (45335857612)
US-NJ-Jersey City: UNIX Developer, UNIX, Shell scripting, SwiftAlliance Access; (45335857612) ============================================================================================= Position: UNIX Developer Reference: SMC01885 Location: Jersey City NJ Duration: 7M Skills: Knowledge of SwiftAlliance Access. Exp in upgrading/migrating Swift Alliance Access, Swift Alliance Gateway, SwiftNet Link. Knowledge of Compliance and Watchlist filtering applications like Mircosoft. Knowledge of B...

US-NJ-Jersey City: UNIX Developer, UNIX, Shell scripting, SwiftAlliance Access; (45335557609)
US-NJ-Jersey City: UNIX Developer, UNIX, Shell scripting, SwiftAlliance Access; (45335557609) ============================================================================================= Position: UNIX Developer Reference: SMC01885 Location: Jersey City NJ Duration: 7M Skills: Knowledge of SwiftAlliance Access. Exp in upgrading/migrating Swift Alliance Access, Swift Alliance Gateway, SwiftNet Link. Knowledge of Compliance and Watchlist filtering applications like Mircosoft. Knowledge of B...

US-NJ-Jersey City: UNIX Developer, UNIX, Shell scripting, SwiftAlliance Access; (45335832409)
US-NJ-Jersey City: UNIX Developer, UNIX, Shell scripting, SwiftAlliance Access; (45335832409) ============================================================================================= Position: UNIX Developer Reference: SMC01885 Location: Jersey City NJ Duration: 7M Skills: Knowledge of SwiftAlliance Access. Exp in upgrading/migrating Swift Alliance Access, Swift Alliance Gateway, SwiftNet Link. Knowledge of Compliance and Watchlist filtering applications like Mircosoft. Knowledge of Banking, payme...

US-NJ-Jersey City: UNIX Developer, UNIX, Shell scripting, SwiftAlliance Access; (45335814411)
US-NJ-Jersey City: UNIX Developer, UNIX, Shell scripting, SwiftAlliance Access; (45335814411) ============================================================================================= Position: UNIX Developer Reference: SMC01885 Location: Jersey City NJ Duration: 7M Skills: Knowledge of SwiftAlliance Access. Exp in upgrading/migrating Swift Alliance Access, Swift Alliance Gateway, SwiftNet Link. Knowledge of Compliance and Watchlist filtering applications like Mircosoft. Knowledge of B...

US-NJ-Jersey City: UNIX Developer, UNIX, Shell scripting, SwiftAlliance Access; (45335557609)
US-NJ-Jersey City: UNIX Developer, UNIX, Shell scripting, SwiftAlliance Access; (45335557609) ============================================================================================= Position: UNIX Developer Reference: SMC01885 Location: Jersey City NJ Duration: 7M Skills: Knowledge of SwiftAlliance Access. Exp in upgrading/migrating Swift Alliance Access, Swift Alliance Gateway, SwiftNet Link. Knowledge of Compliance and Watchlist filtering applications like Mircosoft. Knowledge of B...

US-NJ-Jersey City: UNIX Developer, UNIX, Shell scripting, SwiftAlliance Access; (45335553540)
US-NJ-Jersey City: UNIX Developer, UNIX, Shell scripting, SwiftAlliance Access; (45335553540) ============================================================================================= Position: UNIX Developer Reference: SMC01885 Location: Jersey City NJ Duration: 7M Skills: Knowledge of SwiftAlliance Access. Exp in upgrading/migrating Swift Alliance Access, Swift Alliance Gateway, SwiftNet Link. Knowledge of Compliance and Watchlist filtering applications like Mircosoft. Knowledge of B...

US-NJ-Jersey City: UNIX Developer, UNIX, Shell scripting, SwiftAlliance Access; (45335553540)
US-NJ-Jersey City: UNIX Developer, UNIX, Shell scripting, SwiftAlliance Access; (45335553540) ============================================================================================= Position: UNIX Developer Reference: SMC01885 Location: Jersey City NJ Duration: 7M Skills: Knowledge of SwiftAlliance Access. Exp in upgrading/migrating Swift Alliance Access, Swift Alliance Gateway, SwiftNet Link. Knowledge of Compliance and Watchlist filtering applications like Mircosoft. Knowledge of B...

US-NJ-Jersey City: UNIX Developer, UNIX, Shell scripting, SwiftAlliance Access; (45335832409)
US-NJ-Jersey City: UNIX Developer, UNIX, Shell scripting, SwiftAlliance Access; (45335832409) ============================================================================================= Position: UNIX Developer Reference: SMC01885 Location: Jersey City NJ Duration: 7M Skills: Knowledge of SwiftAlliance Access. Exp in upgrading/migrating Swift Alliance Access, Swift Alliance Gateway, SwiftNet Link. Knowledge of Compliance and Watchlist filtering applications like Mircosoft. Knowledge of B...

US-NJ-Jersey City: UNIX Developer, UNIX, Shell scripting, SwiftAlliance Access; (45335857612)
US-NJ-Jersey City: UNIX Developer, UNIX, Shell scripting, SwiftAlliance Access; (45335857612) ============================================================================================= Position: UNIX Developer Reference: SMC01885 Location: Jersey City NJ Duration: 7M Skills: Knowledge of SwiftAlliance Access. Exp in upgrading/migrating Swift Alliance Access, Swift Alliance Gateway, SwiftNet Link. Knowledge of Compliance and Watchlist filtering applications like Mircosoft. Knowledge of B...

US-NJ-Jersey City: UNIX Developer, UNIX, Shell scripting, SwiftAlliance Access; (45335557609)
US-NJ-Jersey City: UNIX Developer, UNIX, Shell scripting, SwiftAlliance Access; (45335557609) ============================================================================================= Position: UNIX Developer Reference: SMC01885 Location: Jersey City NJ Duration: 7M Skills: Knowledge of SwiftAlliance Access. Exp in upgrading/migrating Swift Alliance Access, Swift Alliance Gateway, SwiftNet Link. Knowledge of Compliance and Watchlist filtering applications like Mircosoft. Knowledge of B...

US-NJ-Jersey City: UNIX Developer, UNIX, Shell scripting, SwiftAlliance Access; (45335814411)
US-NJ-Jersey City: UNIX Developer, UNIX, Shell scripting, SwiftAlliance Access; (45335814411) ============================================================================================= Position: UNIX Developer Reference: SMC01885 Location: Jersey City NJ Duration: 7M Skills: Knowledge of SwiftAlliance Access. Exp in upgrading/migrating Swift Alliance Access, Swift Alliance Gateway, SwiftNet Link. Knowledge of Compliance and Watchlist filtering applications like Mircosoft. Knowledge of B...

US-NJ-Jersey City: UNIX Developer, UNIX, Shell scripting, SwiftAlliance Access; (45335832409)
US-NJ-Jersey City: UNIX Developer, UNIX, Shell scripting, SwiftAlliance Access; (45335832409) ============================================================================================= Position: UNIX Developer Reference: SMC01885 Location: Jersey City NJ Duration: 7M Skills: Knowledge of SwiftAlliance Access. Exp in upgrading/migrating Swift Alliance Access, Swift Alliance Gateway, SwiftNet Link. Knowledge of Compliance and Watchlist filtering applications like Mircosoft. Knowledge of B...

US-NJ-Jersey City: UNIX Developer, UNIX, Shell scripting, SwiftAlliance Access; (45335857612)
US-NJ-Jersey City: UNIX Developer, UNIX, Shell scripting, SwiftAlliance Access; (45335857612) ============================================================================================= Position: UNIX Developer Reference: SMC01885 Location: Jersey City NJ Duration: 7M Skills: Knowledge of SwiftAlliance Access. Exp in upgrading/migrating Swift Alliance Access, Swift Alliance Gateway, SwiftNet Link. Knowledge of Compliance and Watchlist filtering applications like Mircosoft. Knowledge of B...

US-NJ-Jersey City: UNIX Developer, UNIX, Shell scripting, SwiftAlliance Access; (45335553540)
US-NJ-Jersey City: UNIX Developer, UNIX, Shell scripting, SwiftAlliance Access; (45335553540) ============================================================================================= Position: UNIX Developer Reference: SMC01885 Location: Jersey City NJ Duration: 7M Skills: Knowledge of SwiftAlliance Access. Exp in upgrading/migrating Swift Alliance Access, Swift Alliance Gateway, SwiftNet Link. Knowledge of Compliance and Watchlist filtering applications like Mircosoft. Knowledge of B...

US-NJ-Jersey City: UNIX Developer, UNIX, Shell scripting, SwiftAlliance Access; (45335814411)
US-NJ-Jersey City: UNIX Developer, UNIX, Shell scripting, SwiftAlliance Access; (45335814411) ============================================================================================= Position: UNIX Developer Reference: SMC01885 Location: Jersey City NJ Duration: 7M Skills: Knowledge of SwiftAlliance Access. Exp in upgrading/migrating Swift Alliance Access, Swift Alliance Gateway, SwiftNet Link. Knowledge of Compliance and Watchlist filtering applications like Mircosoft. Knowledge of Banking, payme...

Convert Bash shell script to Korn shell script
The following bash script works fine to delete all files that are older than $1 minutes. To execute this script, bash cleanup +10 find /mypath -type f -cmin $1 -exec rm -f {} \; Unfortunately, now I just realize I need to make it work in Korn Shell. Even I change the header from #!/bin/bash to #!/usr/bin/ksh, and execute the script by ksh cleanup +10, it still have different errors: cleanup[9]: -cmin: not found. cleanup[10]: -type: not found. Looks like it doesn't work anymore. I think I need to re-write the Korn Shell script that do the task. I tried to search for equivalent Korn ...

Convert Bash shell script to Korn shell script
The following bash script works fine to delete all files that are older than $1 minutes. To execute this script, bash cleanup +10 find /mypath -type f -cmin $1 -exec rm -f {} \; Unfortunately, now I just realize I need to make it work in Korn Shell. Even I change the header from #!/bin/bash to #!/usr/bin/ksh, and execute the script by ksh cleanup +10, it still have different errors: cleanup[9]: -cmin: not found. cleanup[10]: -type: not found. Looks like it doesn't work anymore. I think I need to re-write the Korn Shell script that do the task. I tried to search for equivalent Korn ...

help needed how can connect to my oracle database using shell script and how can i assign particular value in table to a variable defined in shellscript
help needed how can connect to my oracle database using shell script and how can i assign particular value in table to a variable defined in shellscript "mahesh" <mahesh2425@gmail.com> wrote in message news:1163830011.873349.304780@k70g2000cwa.googlegroups.com... : help needed how can connect to my oracle database using shell script : and how can i assign particular value in table to a variable defined in : shellscript : Hunt around your oracle installation and you will find tons of shell scripts that will give you all the ideas you need. Dan Mercer ...

Web resources about - Can a script nohup itself? - comp.unix.shell

This photo of Mark Zuckerberg with a VR army is disturbingly Orwellian
The image is delightfully and disturbingly apt: Mark Zuckerberg confidently striding alongside a crowd of seated people all wearing virtual reality ...

Tim Cook says Apple's dispute with FBI is best handled this way
CNET Tim Cook says Apple's dispute with FBI is best handled this way CNET A note supporting Apple hangs on window of a San Francisco Apple ...

Donald Trump’s ‘outlandish’ persona might be due to his decades-long relationship with WWE
"Never Enough: Donald Trump and the Pursuit of Success" author Michael D'Antonio recently stopped by Business Insider to discuss his book on ...

EU referendum: David Cameron treats Boris Johnson to the thrashing of his life
POLITICAL SKETCH: Before an astonished Commons, the Prime Minister savages the Mayor of London over his decision to campaign for Brexit

Eric Boehlert: Hours After Michigan Gun Rampage, The Sunday Shows All Ignore Kalamazoo Killings
Police say Jason Dalton began his killing spree at 5:42 p.m. when the Uber driver from Kalamazoo, Michigan, shot a woman multiple times as she ...

IBM brings Swift to the cloud, releases web framework Kitura written in Apple’s programming language
Only months after Apple officially open-sourced Swift , IBM today is announcing that they are bringing Apple’s Swift programming language to ...

Bernie Sanders Wanted to Abolish the CIA—Good!
The CIA has a long history of torture, assassination, botched regime change, extrajudicial executions, opaque drone slaughter, and general disdain ...

US, Russia Agree on Plan for Syria Cease-Fire
The Express Tribune US, Russia Agree on Plan for Syria Cease-Fire New York Times DAMASCUS, Syria — U.S. officials said Monday that the United ...

Here's a Video Where Kanye West Gets Tired From Running in a Room
A decade (it seems) after we first heard about it, Kanye West has released the video for “All Day/I Feel Like That,” songs that aren’t on his ...

Denny Hamlin's childhood letter proves dreams come true
Denny Hamlin wanted to win the Daytona 500. On Feb. 21, he did.

Resources last updated: 2/22/2016 6:18:28 PM