Results 1 to 5 of 5
-
06-08-2005, 12:43 PM #1Junior Guru
- Join Date
- Nov 2002
- Posts
- 202
[bash/linux] single script instance running only
I have a bash script which runs in the crontab every 5 minutes.
I want the script to only execute if a current instance of the script is not already running. If it's already running/processing, then to do nothing.
Whats a good way to do this?
-
06-08-2005, 12:47 PM #2Junior Guru
- Join Date
- Nov 2002
- Posts
- 202
I have an idea of using the following code:
PHP Code:ps u | grep script.sh | awk '{print $11}'
1. how do i grep a path name like "/usr/local/program.sh"
Cheers!
-
06-10-2005, 01:53 PM #3Junior Guru
- Join Date
- Dec 2002
- Posts
- 242
process=`ps auxw | grep script.sh | grep -v grep | awk '{print $11}'`
if [ -z "$process" ]; then
/path/to/your/script.sh
fi
Try this?
-
06-10-2005, 06:51 PM #4PHP for breakfast
- Join Date
- May 2004
- Location
- Lansing, MI, USA
- Posts
- 1,548
Code:if [ -f /path/to/lockfile ] then echo Lock file found... else touch /path/to/lockfile ... code ... rm -f /path/to/lockfile fi
Jacob - WebOnce Technologies - 30 Day 100% Satisfaction Guarantee - Over 5 Years Going Strong!
Website Hosting, PHP4&5, RoR, MySQL 5.0, Reseller Hosting, Development, and Designs
Powered By JAM - Professional Website Development - PHP, MySQL, JavaScript, AJAX - Projects Small & Large
-
06-10-2005, 10:31 PM #5Junior Guru
- Join Date
- Nov 2002
- Posts
- 202
intelligent, thanks webonce