- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- How to the background job is running or not?
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2002 07:16 PM
07-30-2002 07:16 PM
How to the background job is running or not?
I have write a script that will run another script in backupground.(e.g. a.sh &). Sometime a.sh seem to be hang up. Thus, how can i trace or determine this background is run successfully or failed.
Thanks
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2002 07:41 PM
07-30-2002 07:41 PM
Re: How to the background job is running or not?
A simple method would be to create a wrapper script:
# cat wrapper.sh
a.sh
echo $? > /tmp/a.sh.status
The wrapper script will store the exit code of a.sh into /tmp/a.sh.status
In your main script e.g. main.sh:
# cat main.sh
wrapper.sh &
while sleep 5
do
if grep 0 /tmp/a.sh.status >/dev/null 2>&1
then
echo a.sh has completed successfully
exit 0
fi
done
This is just one method. Hope this helps. Regards.
Steven Sim Kok Leong
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2002 07:41 PM
07-30-2002 07:41 PM
Re: How to the background job is running or not?
You should have a log file for any scripts that you run.
like a.sh & >/tmp/log 2>&1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2002 03:26 AM
07-31-2002 03:26 AM
Re: How to the background job is running or not?
Let a.sh create a "lock file" as soon as it starts up to indicate that it is running. Just before exiting, it should delete this lock file.
a.sh will look like this:
#!/usr/bin/ksh
touch $HOME/lock_file
...do your stuff here...
rm -f $HOME/lock_file
Just before calling a.sh, delete any old lock file that may be present. As long as the lock file exists, you can assume that the backgroung process is running.
You can also add a trp statement in a.sh like so:
trap 'rm -f $HOME/lock_file; exit 1' 2 15

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2002 04:17 AM
07-31-2002 04:17 AM
Re: How to the background job is running or not?
ksh -x a.sh > /tmp/a.log 2>&1 &
The -x option to ksh will cause it to display all commands (and their output) that it runs to the specified log file
cat /tmp/a.log
+ TERM=vt320
+ PS1=[$HOSTNAME] ${PWD##${PWD%/*/*}/} =>
+ [ -f /home/chris/.profile ]
+ echo 1111
1111
+ echo 2222
2222