Shell script emailing issue


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Shell script emailing issue
# 1  
Old 03-06-2012
Shell script emailing issue

Hi,

Im writing a shell script:

Code:
#!/bin/bash
#Send process which has exceeded 25%
#
echo 'pri pid user nice pcpu command' > /export/home/tjmoore/file2
#
if ps -eo pri,pid,user,nice,pcpu,comm | awk '{if($5 >= 25)print $0}' >> /export/home/tjmoore/file2 2>/dev/null
#
#
#
then /usr/local/bds/mailsend.s mailx "Process has surpassed 25% threshold" [email adress] [email address] /export/home/tjmoore/file2 2&1>/dev/null
fi

my issue is that it sends an email even if there is no process exceeding the threshold, is there anyway I can stop this from happening possibly by using a grep along with a sed command or grepping for a range of numbers in the file before it is sent?

Last edited by methyl; 03-06-2012 at 01:32 PM.. Reason: please use code tags ; correct paste errors
# 2  
Old 03-06-2012
Try breaking the script into stages.
Something like this (untested).

Code:
#!/bin/bash
#Send process which has exceeded 25%
#
echo 'pri pid user nice pcpu command' > /export/home/tjmoore/file2
ps -eo pri,pid,user,nice,pcpu,comm | awk '{if($5 >= 25)print $0}' >> /export/home/tjmoore/ps_file2 2>/dev/null
#
if [ -s /export/home/tjmoore/ps_file2 ]
then
    cat /export/home/tjmoore/ps_file2 >> /export/home/tjmoore/file2
    /usr/local/bds/mailsend.s mailx "Process has surpassed 25% threshold" [email adress] [email address] /export/home/tjmoore/file2 2&1>/dev/null
fi

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Issue with emailing format from UNIX

Need help as to why when I try email the following it does not come out right: DateOt=`date +"%a %b %d %T %Y"` TimeOt=`date +%H:%M:%S` interval=`cat $SecDiff| awk '{print $3}'` PortInReq2=`cat /shared/ftpdir/tools/quelog/logs/quelog.NPS_TO_SMG.log | grep PQI | wc -l` PortInRes2=`cat... (2 Replies)
Discussion started by: mrn6430
2 Replies

2. Shell Programming and Scripting

Issue in shell script

item,quantity,unit price,total tea,1,1,1 coffee,3,4,12 sugar,5,2.5,12.5 tea,2,1,3 coffee,2,4,8 i have got the above file with following questions: need to get the total value: which i got using : a=0 for b in `cut -f4 -d ',' log` do c=`echo $a + $b | bc` a=$c done echo "$a and $c" ... (9 Replies)
Discussion started by: bhupeshchavan
9 Replies

3. UNIX for Dummies Questions & Answers

Emailing results of a pl sql procedure from UNIX shell script

Hello All, I am writing the below unix script to email the result of a small pl sql procedure: #!/bin/bash ORACLE_HOME=/opt/oracle/orcts/product/9.2.0; export ORACLE_HOME SQLPLUS=$ORACLE_HOME/bin/sqlplus sqlplus -s user/pass@Db_instance<<EOF set echo off set feedback off set pages 0... (9 Replies)
Discussion started by: Bunty bedi
9 Replies

4. Shell Programming and Scripting

Issue with shell script

I found a post from a user requesting help rounding numbers. The script provided by Scrutinizer works fine most of the time but it errors out when trying to round these numbers: 30224939 50872456 20753012 They have in common, a zero in the second digit from left to right. Can someone help... (1 Reply)
Discussion started by: Dennis_Ayala
1 Replies

5. Shell Programming and Scripting

CLI script for emailing alert if files missing in dir

thread removed (4 Replies)
Discussion started by: billabongjimmy
4 Replies

6. Shell Programming and Scripting

Issue in TC Shell Script

I have a script in TC shell, for some reason its not working. I'm trying to kick off a script if there are any files in a particular directory "/sample/test3" Can anyone point out the issue in the same #!/usr/bin/tcsh while true do if ls /sample/test3 >& /dev/null ; then... (2 Replies)
Discussion started by: gaugeta
2 Replies

7. Shell Programming and Scripting

Automate emailing via shell script

Hi, I am struggling to send my email via shell script. I can type the command in and it works pefectly: mail -s "subject" email@email.co.email < text_to_sendHowever if I try and automate it it fails. I have tried setting variables for all aspects (mail, email addr, subject, message) with no... (3 Replies)
Discussion started by: mcclunyboy
3 Replies

8. Shell Programming and Scripting

Help me with following issue using shell script

Hi Folks, I am looking for a script where that should show the progress bar while running a process Ex: while copying a file of size say 2 GB it should start the process as (0 %) and at the end it should show (100%) Thanks in Advance Phani. (4 Replies)
Discussion started by: phanivarma
4 Replies

9. Shell Programming and Scripting

script not emailing or running

Hi, I am having trouble with this script. It is suppose to send me an email when the specified tablespace is 60% full. I run it but nothing happens FREESPACELOG=/home/oracle/scripts/bin/free_space/freespace.sql email=bob@bob.edu subject="PROD: Tablespace Free Space" cmd="mailx -s... (1 Reply)
Discussion started by: shaseeb
1 Replies

10. UNIX for Dummies Questions & Answers

SMTP - emailing issue

We are running an application engine program that sends email to a list of users. In our Test Env, users are able to receive the emails but in our Prod environment, they do not. We are running the same program, and using the same stmp config. any idea on how to troubleshoot? (3 Replies)
Discussion started by: tads98
3 Replies
Login or Register to Ask a Question