Shell Script Consolidation, Part 2
The logic of the original script is basically to ensure the script has to be executed by a specific user. Also, it will try to find out the status of the process before taking any action (start, stop). Suppose we have:
- INSTANCE 1
Install Directory: /opt/middleware/u01
User: "user1"
Executable: /opt/middleware/u01/bin/cms.exe
Start/Stop script: /opt/scripts/u01/cms.sh - INSTANCE 2
Install Directory: /opt/middleware/u02
User: "user2"
Executable: /opt/middleware/u02/bin/cms.exe
Start/Stop script: /opt/scripts/u02/cms.sh
The original startup/stop script for the middleware somehow uses an "inverted match" (-v in grep) to check for the existence of process
RUN=`ps auxwww | grep cms.exe | grep -v grep | grep
Although the above command sequence is not foolproof way to locate the correct process, the inverted match managed to work in this case with two instances of the middleware. What will happen if we were to have 3 or more instances running in the same hardware ? I will leave this to my reader to figure that out :-)
In Linux or even in Solaris, you can have a foolproof way to locate the process. The commands that you want to explore are
pgrep and pkill
The return code of 0 (zero) from pgrep -u user1 cms.exe > /dev/null 2>&1
will indicate the process "cms.exe" own by "user1" exist.
By right we should only have one set of scripts to handle all the middleware, but "by left" ...
Labels: shell script
0 Comments:
Post a Comment
<< Home