how to get the status from scripts running in the background

  • Follow


I need to:

1. run several scripts concurrently
2. wait until they are done
3. get the exit status
4. If one fails, then I need to do some error handling.
5. its also redirecting to nohup.out

nohup run_sql $ERROR_MSG_OPTION -u $LOGIN_FILE_NAME $SQL_SCRIPT1 2>&1
> sql_script1.log;
message "$? $SQL_SCRIPT1" $STATUS_FILE &
nohup run_sql $ERROR_MSG_OPTION -u $LOGIN_FILE_NAME $SQL_SCRIPT2 2>&1
>  sql_script1.log;
message "$? SQL_SCRIPT2" $STATUS_FILE &
wait


$STATUS_FILE is just a file, I need to grep for errors. This works,
but it does not run concurrently in the background and I get
'redirected to nohup.out'

this is korn shell.
-1
Reply rgaffuri (218) 5/24/2004 3:26:30 PM

In article <1efdad5b.0405240726.3c6997d0@posting.google.com>,
 rgaffuri@cox.net (Ryan Gaffuri) wrote:

> I need to:
> 
> 1. run several scripts concurrently
> 2. wait until they are done
> 3. get the exit status
> 4. If one fails, then I need to do some error handling.
> 5. its also redirecting to nohup.out

If you use "wait <pid>", it waits for that background process to finish, 
and the exit status of this command is the exit status of the background 
process.

-- 
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
0
Reply Barry 5/24/2004 9:29:19 PM


Barry Margolin <barmar@alum.mit.edu> wrote in message news:<barmar-995940.17291924052004@comcast.dca.giganews.com>...
> In article <1efdad5b.0405240726.3c6997d0@posting.google.com>,
>  rgaffuri@cox.net (Ryan Gaffuri) wrote:
> 
> > I need to:
> > 
> > 1. run several scripts concurrently
> > 2. wait until they are done
> > 3. get the exit status
> > 4. If one fails, then I need to do some error handling.
> > 5. its also redirecting to nohup.out
> 
> If you use "wait <pid>", it waits for that background process to finish, 
> and the exit status of this command is the exit status of the background 
> process.


two questions:

1. how do i get the pid of a process running in the background
2. what if i want to wait for many background processes?
0
Reply rgaffuri 5/25/2004 7:29:56 PM

In article <1efdad5b.0405251129.386d06c8@posting.google.com>,
 rgaffuri@cox.net (Ryan Gaffuri) wrote:

> Barry Margolin <barmar@alum.mit.edu> wrote in message 
> news:<barmar-995940.17291924052004@comcast.dca.giganews.com>...
> > In article <1efdad5b.0405240726.3c6997d0@posting.google.com>,
> >  rgaffuri@cox.net (Ryan Gaffuri) wrote:
> > 
> > > I need to:
> > > 
> > > 1. run several scripts concurrently
> > > 2. wait until they are done
> > > 3. get the exit status
> > > 4. If one fails, then I need to do some error handling.
> > > 5. its also redirecting to nohup.out
> > 
> > If you use "wait <pid>", it waits for that background process to finish, 
> > and the exit status of this command is the exit status of the background 
> > process.
> 
> 
> two questions:
> 
> 1. how do i get the pid of a process running in the background

$! expands to the PID of the last background process that was started.

> 2. what if i want to wait for many background processes?

You can use wait without an argument to wait for all background 
processes, but then you can't get their statuses.

You could have each background process write its exit status to a file 
when it's done, e.g.

(some_command; echo $? > /tmp/some_command.exit) &

-- 
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
0
Reply Barry 5/25/2004 8:33:04 PM

3 Replies
869 Views

(page loaded in 0.144 seconds)

Similiar Articles:













7/22/2012 10:09:44 AM


Reply: