script to list out the output in one paragraph


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting script to list out the output in one paragraph
# 1  
Old 06-25-2008
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.
# 2  
Old 06-25-2008
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.
# 3  
Old 06-26-2008
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?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Need list of input and output parameter of task in a text file, using shell script

//file begin ===== //some code task abcd_; input x; input y,z; //some comment output w; //some comment reg p; integer q; begin //some code end endtask : abcd_ //some code //file end ===== expected output from above... (1 Reply)
Discussion started by: rishifrnds
1 Replies

2. Shell Programming and Scripting

Bash script to extract paragraph with globs in it

Hi, Its been a long time since I have used Bash to write a script so am really struggling here. Need the gurus to help me out. uname -a Linux lxserv01 2.6.18-417.el5 i have a text file with blocks of code written in a similar manner ******* BEGIN MESSAGE ******* Station /... (12 Replies)
Discussion started by: dsid
12 Replies

3. Shell Programming and Scripting

script to mail monitoring output if required or redirect output to log file

Below script perfectly works, giving below mail output. BUT, I want to make the script mail only if there are any D-Defined/T-Transition/B-Broken State WPARs and also to copy the output generated during monitoring to a temporary log file, which gets cleaned up every week. Need suggestions. ... (4 Replies)
Discussion started by: aix_admin_007
4 Replies

4. Shell Programming and Scripting

Awk script to run a sql and print the output to an output file

Hi All, I have around 900 Select Sql's which I would like to run in an awk script and print the output of those sql's in an txt file. Can you anyone pls let me know how do I do it and execute the awk script? Thanks. (4 Replies)
Discussion started by: adept
4 Replies

5. UNIX for Dummies Questions & Answers

Output text from 1st paragraph in file w/ a specific string through last paragraph of file w/ string

Hi, I'm trying to output all text from the first paragraph in a file that contains a specific string through the last paragraph in that file that contains that string. Previously, I was outputting just each paragraph with that search string with: cat in_file | nawk '{RS=""; FS="\n";... (2 Replies)
Discussion started by: carpenn
2 Replies

6. Shell Programming and Scripting

I need a script to find socials in files and output a list of those files

I am trying to find socail security numbers in files in (and under) a specific directory and output a list of the files where they are found... the format would be with no dashes just 9 numeric characters in a row. I have tried this: find /DirToLookIn -exec grep '\{9\}' /dev/null {} \; >>... (1 Reply)
Discussion started by: NewSolarisAdmin
1 Replies

7. Shell Programming and Scripting

Need your HELP:: Shell script to detect paragraph in coordinate-based code.

Hi Friends!! I have obtained following output from a tool called pdftoxml: <xml> <text top="423" left="521" width="333" height="20" font="3">Although the the number of fuzzy rules of a system is </text> <text top="441" left="500" width="355" height="20" font="3">directly dependant on these... (2 Replies)
Discussion started by: parshant_bvcoe
2 Replies

8. UNIX for Dummies Questions & Answers

Split a paragraph

Hi, Consider the following paragraph. This is line1. This is line2, This is last line. I need the output as 4:This is last line. i.e The line after the blank line should be displayed along with line number. I am a unix begineer.Any one please help me to solve this problem (3 Replies)
Discussion started by: Sekar1
3 Replies

9. Shell Programming and Scripting

script for a 3 line paragraph

i would like to ask how to make a script that in evry 3 lines of my paragraph(below) it would appear like this: $ cat myparagraph this is line 1 this is line 2 this is line3 this is line 4 this is 5 this 6 this is 7 this 8 ==================================================== $ cat... (2 Replies)
Discussion started by: invinzin21
2 Replies

10. Shell Programming and Scripting

Bold the paragraph

Hi, I have a file with multiple paragraph. I want to look for some word and make that paragraph bold. How can I do that? Thanks, Karthik (3 Replies)
Discussion started by: caprikar
3 Replies
Login or Register to Ask a Question