grep number and sent out e-mail


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting grep number and sent out e-mail
# 1  
Old 10-28-2011
grep number and sent out e-mail

HTML Code:
ps -ef |grep /usr/sbin/qdaemon 
    root 5034194  385266   0   Oct 26      -  1:57 /usr/sbin/qdaemon 
    root 7639132 2523220   0 15:25:58 pts/10  0:00 grep /usr/sbin/qdaemon 
ps -ef |grep /usr/sbin/qdaemon  |wc
       2      18     145
I need to send out e-mail if the count of the lines is larger than 2. Basically, I want to see if more than one qdaemon is running or not.

Please advise.
# 2  
Old 10-28-2011
To get started...

The following tells the number of lines
Code:
ps -ef |grep /usr/sbin/qdaemon |wc -l

verify this
then you can
Code:
cnt=`ps -ef |grep /usr/sbin/qdaemon |wc -l`
echo $cnt

to put the result into a variable

if [ $cnt > 2 ] ; then echo "large"; fi

That is a start.
If you get that far, then you can start experimenting with how to email. That is a separate issue depending on your setup.

Last edited by joeyg; 10-28-2011 at 04:50 PM..
# 3  
Old 10-28-2011
PHP Code:
#!/usr/bin/ksh

cnt=`ps -ef |grep /usr/sbin/qdaemon |wc -l`

if [ 
$cnt -lt 1 ] ; then
    
  mail 
-"$SYSNAME: More than 1 qdaemon running" doe@abc.com

fi 
I thought it would be easy as this, but I am not getting any output.

I am on AIX 5.3.

Please advise.
# 4  
Old 10-28-2011
Code:
#!/usr/bin/ksh

cnt=`ps -ef |grep /usr/sbin/qdaemon |wc -l`

if [ $cnt -gt 1 ] ; then
    
  mailx -s "$SYSNAME: More than 1 qdaemon running" doe@abc.com

fi

This User Gave Thanks to rdcwayx For This Post:
# 5  
Old 10-29-2011
Code:
pgrep -c qdaemon | xargs -I {} test {} -gt 1 && mailx -s "qdaemon is loose" you@you.com

--ahamed
This User Gave Thanks to ahamed101 For This Post:
# 6  
Old 10-31-2011
PHP Code:
#!/usr/bin/ksh

cnt=`ps -ef |grep /usr/sbin/qdaemon |wc -l`

if [ 
$cnt -gt 1 ] ; then
    
  mailx 
-"$SYSNAME: More than 1 qdaemon running" doe@abc.com

fi 
It is odd that this script is hanging on the execution and doing nothing..

When I check it manually, $cnt returns fine though.

PHP Code:
TOC # cnt=`ps -ef |grep /usr/sbin/qdaemon |wc -l`
TOC # echo $cnt

Please advise.
# 7  
Old 10-31-2011
Daniel,

Try this:
Code:
 
 
#!/usr/bin/ksh
 
cnt=`ps -ef |grep /usr/sbin/qdaemon |wc -l`
 
if [ $cnt -gt 1 ] ; then

echo "$SYSNAME: More than 1 qdaemon running" > outputfile
mailx -s "<Subject>" doe@abc.com < outputfile
fi 



Thanks,
Vijay V Menon
This User Gave Thanks to vmenon For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Sifting out mail addresses with grep and regex

Hi there from a newbie. So, I have this huuuge portion of mail addresses with names interlaced.. looks like: "name1" <mail1@domain1.com>, "name2" <mail2@domain2.com> ... Sometimes there are no names, just mailaddress. My thought was to use regex with grep. I saved the list in file ma and... (2 Replies)
Discussion started by: dr_xemacs
2 Replies

2. UNIX for Beginners Questions & Answers

Read a file and send mail based on grep

Hi All, I am having a job and I need to send email when the job is running. On any other case (success,fail) I don't needed to send email. I check with BMC they told they dont have that in the version I am using. So I created a dependent job and grepped for the status and sent email. My... (1 Reply)
Discussion started by: arunkumar_mca
1 Replies

3. Shell Programming and Scripting

Ksh: Send a mail in case grep finds something

I want to search a file if it contains special strings and if yes, the records found should be mailed. I can either do it with a temporary file: /usr/bin/grep somestring somefile > /tmp/tempfile && /usr/bin/mail -s "Found something" email@mycomp.com < /tmp/tempfile... or by running the grep... (10 Replies)
Discussion started by: Cochise
10 Replies

4. Shell Programming and Scripting

Grep lines for number greater than given number

Hello, I am newbie to bash scripting. Could someone help me with the following. I have log file with output as shown below **************************LOG************************* 11/20/2013 9:11:23.64 Pinging xx.xx.xx.xx with 32 bytes of data: 11/20/2013 9:11:23.64 Reply from xx.xx.xx.xx:... (4 Replies)
Discussion started by: meena_2013
4 Replies

5. UNIX for Dummies Questions & Answers

How to grep a string and add to subject line of a mail?

I am running a mailx command as follows in Linux: mailx -s "Elapsed Time: " ora_dbas < $RUNDIR/sql_timings.out I am trying to parse the file "sla_local_sql_timings.out" for the word Elapsed Time: and get the time from that file stored in a variable and display that variable in the subject... (4 Replies)
Discussion started by: vrkcamry
4 Replies

6. Shell Programming and Scripting

Grep the last line and put on mail subject

I have mail: cat /home/oracle/scripts/dbsizedaily.txt | mail -s "$TODAY: PROD DB Size" $RECIPIENTS I like to get and put USED_GB and %USED of the very last row from /home/oracle/scripts/dbsizedaily.txt. /home/oracle/scripts/dbsizedaily.txt has : DATE TIME TOTAL_GB USED_GB ... (6 Replies)
Discussion started by: Daniel Gate
6 Replies

7. Shell Programming and Scripting

Stop sending mail after certain number of mail

Hi guys... I am busy writing a script to notify me via an mail if my application is down. I have done that. Now I want this script to stop sending mails after five mails were sent but the script should keep on checking the application. When the application is up again that count should be... (5 Replies)
Discussion started by: Phuti
5 Replies

8. UNIX for Dummies Questions & Answers

grep any number of spaces

which one of the following is the correct expression to ignore line with multiple spaces after any string cat file | grep -v "xyz *$" or cat file | grep -v "xyz*$" do i need "*" to specify the sapce or " *" will do? (2 Replies)
Discussion started by: manishma71
2 Replies

9. Shell Programming and Scripting

how to grep the time of the mail received?

Hi all, My question is how can we grep the time of the mail which we receive in our inbox? like if i get a mail tonight at 10 i should be able to grep the time of it tomorrow morning or someother day in 24 hr format.... how can we do that? (2 Replies)
Discussion started by: smarty86
2 Replies

10. Shell Programming and Scripting

Grep for a negative number

Hi, I want to search for a return code of -3. Using grep "-3" *.* is giving a syntax error. Please suggest as to how can we search for this pattern using grep. Thanks, Krishna (2 Replies)
Discussion started by: kzmatam
2 Replies
Login or Register to Ask a Question