![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Run a shell script from one host which connext to remote host and run the commands | SN2009 | Shell Programming and Scripting | 6 | 04-13-2009 05:39 AM |
| Kill the running program | akhtar.bhat | Shell Programming and Scripting | 1 | 12-26-2008 07:48 AM |
| Script to kill rsh processes running for more than 10 mins | amitsayshii | UNIX for Dummies Questions & Answers | 3 | 07-04-2006 01:45 PM |
| script to kill rsh processes running for more than 10 minutes | amitsayshii | Shell Programming and Scripting | 1 | 06-27-2006 11:12 AM |
| script to kill rsh processes running for more than 10 minutes | amitsayshii | UNIX for Advanced & Expert Users | 1 | 06-27-2006 11:07 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Kill shell script when host program not running/disk unmounted
I have my Mac OS X program executing a shell script (a script that copies files to a drive). I want to make it so that the shell script automatically kills itself if it finds that the host .app is not running OR kill itself if the drive that it is copying files to has been unmounted. Right now what I have is the shell script polls using the UNIX "ps" command every time before it executes a command, and then kills itself if the app, and then also uses the "df" utility to check if the disk is mounted. like this: Code:
#!/bin/sh
checkrunning()
{
PS=$( /bin/ps -aex )
if [[ $PS != */Contents/MacOS/MyAppBinary* ]]
then
exit 0
fi
DISKS=$( /bin/df | grep "$VOLPATH" )
if [[ $DISKS != *"$1"* ]]
then
exit 0
fi
}
checkrunning
cp /something /something/here/
checkrunning
cp /anothersomething /something/here/
However this polling wastes resources, so is there a better way to do this? I'm using Mac OS X 10.6 using the default shell. |
|
||||
|
Quote:
You could maybe better target the .app application by using the -C option if provided by your OS: Code:
if ps -C firefox-bin ;then echo "Firefox running" fi Just to make sure that I understand your question correctly: the application you are checking, is that the script itself or an external application? If it is the very same script you want to check the running status of, you can just use a file as a lock. You create a empty file at the beginning of the script and rm it at the end. |
![]() |
| Bookmarks |
| Tags |
| kill, polling, shell-script |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|