On Wed, Jun 20, 2007 at 09:54:20AM -0700, MiKe McClain wrote:
> Is there a way for a script to background itself?

Not as such - but you can play trick by having the script re-invoke 
itself:

    #!/bin/bash

    if test -t 0 ; then
        nohup $0 "$@" &
        exit 0
    fi

    echo Doing stuff ...

Or schedule itself as a background job, so the output gets mailed to the 
invoker:
    #!/bin/bash

    if test -t 0 ; then
        # Won't play nice if the parameters have spaces in them - 
        # quoting is removed...
        echo $0 "$@" | batch
        exit 0
    fi

    echo foobar was here

There's probably other ways too.

Since the shell won't wait for the script to finish, you won't get the 
exit code of it though...

Hope this helps
-- 
Karl E. Jorgensen
[EMAIL PROTECTED]  http://www.jorgensen.org.uk/
[EMAIL PROTECTED]     http://karl.jorgensen.com
==== Today's fortune:
The only way to keep your health is to eat what you don't want, drink what
you don't like, and do what you'd rather not.
                -- Mark Twain

Attachment: signature.asc
Description: Digital signature

Reply via email to