![]() |
|
|
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 |
| Split a paragraph | Sekar1 | UNIX for Dummies Questions & Answers | 3 | 06-05-2008 01:35 PM |
| Extract a paragraph | capri_drm | Linux | 2 | 06-04-2008 04:01 PM |
| help, using awk to get paragraph | kunimi | Shell Programming and Scripting | 6 | 06-04-2008 07:56 AM |
| script for a 3 line paragraph | invinzin21 | Shell Programming and Scripting | 2 | 12-18-2007 01:11 AM |
| Bold the paragraph | caprikar | Shell Programming and Scripting | 3 | 12-22-2003 06:44 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
script to list out the output in one paragraph
Hi All,
I want to run 5 `ps -ef | grep [process]` cmds in one script and i want the script to give me return code 0 if everything is OK. If it notices one of the processes is not there, it will prompt me the process name and advice me to check it. I've wrote a script that separates the output but I want to combine it into one output. echo "\n***------------------------------***" echo "\nNo. 8" echo "To check WAS-server1 process.." varB=`ps -ef | grep server1` if [ $? -eq 0 ] then echo "OK, WAS-server1 process is up." else echo "==>NOT OK; WAS-server1 PROCESS IS DOWN, please check!!" fi sleep 3 echo "\n***------------------------------***" echo "\nNo. 9" echo "To check tws process.." varC=`ps -ef | grep tws` if [ $? -eq 0 ] then echo "OK, tws processes are up." else echo "==>NOT OK; tws PROCESS IS DOWN, please check!!" fi sleep 3 And the output is; No. 8 To check WAS-server1 process.. OK, WAS-server1 process is up. ***------------------------------*** No. 9 To check tws process.. OK, tws processes are up. I want the output to be like this; (If all processes are up) Checking all processes.. Return code : 0 All processes are up, OK. (If one of the processes in not up) Checking all processes.. WAS-server1 is UP, OK. ==> TWS is not UP, PLEASE CHECK!! Please help, thank you. |
|
||||
|
Your first problem is that Code:
ps -ef|grep whatever will always be successful resulting in $? being always 0, because of your grep process itself. You could try grep -C process name if you know the actual command for the process you are looking for. As for the output, you could collect the names of all the processes in two lists, e.g. something along the lines of Code:
ps -C $process > /dev/null
if[ $? -eq 0 ]
then
procs_up="$procs_up $process"
else
procs_down="$procs_down $process"
fi
if [ ${#procs_down} -eq 0 ]
then
echo All processes are up, OK.
else
for p in $procs_up
do
echo "$p is up. OK"
done
for p in $procs_down
do
echo "$p is not up. please check"
done
fi
You could also usefully put the process checking bit into a function. |
|
||||
|
spirtle,
I tried with single process first; root@axdevt01::/tmp/fara/script> cat grep2.sh #process=df process=server1 ps -ef | grep $process | grep -v grep > /dev/null if [ $? -eq 0 ] then procs_up="$procs_up $process" else procs_down="$procs_down $process" fi if [ ${procs_down} -eq 0 ] then echo All processes are up, OK. else for p in $procs_up do echo "$p is up. OK" done for p in $procs_down do echo "$p is not up. please check" done fi And this is the output; root@axdevt01::/tmp/fara/script> grep2.sh grep2.sh[12]: test: argument expected server1 is up. OK Then I tried df (not server1, df is not up), and this is the output; root@axdevt01::/tmp/fara/script> grep2.sh grep2.sh[12]: df: bad number df is not up. please check Any advise? |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|