Results 1 to 5 of 5
Hi,
I work on many platforms like windows, Linux, Solaris,etc.
I have an executable which can be run from any platform. Now that the process is automated, I have to ...
- 01-08-2008 #1Just Joined!
- Join Date
- Apr 2007
- Posts
- 59
How do I implement this in shell script?
Hi,
I work on many platforms like windows, Linux, Solaris,etc.
I have an executable which can be run from any platform. Now that the process is automated, I have to find out the way to ensure that the exe is run on any one platform at one time.
lets take an example that I have a shell script at some common location, which calls this exe. and this script is run on 3 machines simultaneously.
I came with an idea that just before the start of the exe, the script will create a file "IN_PROCESS" at the common location. and once the exe is exited, the file shoudl be removed. If during running of the exe on one platform, other platform will first check the existence of the file. If file exists then it should wait till the file is non-existent.
But I'm not able to write the logic properly. can somebody help how can i implement this?
Thanks
- 01-08-2008 #2
That's good reasoning. And not at all difficult. You can look at your bootscripts for examples, because they often do the same check before loading services, although they don't look for the existance, but rather the executability (<=new word?) of a file. Their test is '-x' in stead of '-e' in your case. <man test> gives you a full range of options.
In BASH:
In this example code I assume you predefine the variables. You could also hard code them. for exampleCode:# Non-tested example code if [ -e /$PATH/IN_PROCESS ] ; then # If file exists, then echo 'Process already running' # Say it's running and exit $PROCESS_EXISTS # Exit with non-zero status (variable needs to be defined or hard coded) else # Else (if file doesn't exist) /$PATH/$EXE # Start executable fi
exit 1
would be valid. The same goes for $PATH and $EXE
---
Another way to do this is to search through to output of <ps aux> to see if the process is running.Can't tell an OS by it's GUI
- 01-08-2008 #3Just Joined!
- Join Date
- Apr 2007
- Posts
- 59
I do not want to exit if that process is running. It should wait till that file is non-existent.
I have used this logic:
Also, can you please tell me what is the difference between '-e' and '-f'.Code:while test -f $PATH/IN_PROCESS do echo "Process already running" done touch $PATH/IN_PROCESS /$PATH/$EXE rm -f $PATH/IN_PROCESS
- 01-08-2008 #4
Oh! While rereading your post, I noticed you don't want the script to exit, but rather wait until the file no longer exists. That calls for a different approach.
Code:while [ -e /$PATH/IN_PROCESS ] do sleep 5 done /$PATH/$EXE
This checks every five seconds, and starts the executable after it no longer finds the file.Can't tell an OS by it's GUI
- 01-08-2008 #5
Ah! We where at it at the same time.
The difference between -e and -f isn't really important in this context. -e looks for the existence of a file. -f tests whether the file exists and is a regular file.
Both will come up 'true'
You will want to put the sleep command in there, or your machine will use every and all of it's raw power to fanatically test whether the file is present
Originally Posted by sandeep t
Can't tell an OS by it's GUI


Reply With Quote