Sendmail when a process stops


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sendmail when a process stops
# 1  
Old 06-16-2014
Sendmail when a process stops

I have a process that crashes quite often. I'm unable to fix it since I'm not the developer and it is beyond my control to do so. However restarting the process will fix the issue which is fine.

I would like to receive a notification via email that the process has failed so I can login and restart the process without having to activelymonitor it.

Is this possible to achieve without installing additional software as this is not allowed for my servers? I was thinking of a bash script like the one below without the threshold only when it fails.

swx - is name process name
500- threshold for permitted processes

Code:
#!/bin/ksh
VAL=`ps -ef | grep -c swx | awk ‘{if ( $1 > 500 ) print $1 }'`
if [ "$VAL" -ge "500" ]; then
echo “$VAL user processes found running with SWX user. Exceeded the Threshold,
Please take immediate action.” | /usr/bin/mailx -s “Alert !! $VAL SWX Applicati
on processes” email@test.com
fi
exit 0

You can add this to crontab like below:
Code:
* * * * * /u02/scripts/userprocmon.sh >/dev/null 2>&1

Thanks in advnace for any help provided
# 2  
Old 06-16-2014
It is more a question of having sendmail installed and configured... which I doubt unless your server is a mail server also... but with a bit of luck may be configured to send to mail server...
# 3  
Old 06-17-2014
I did a sendmail test to my work email account and it worked fine.
# 4  
Old 06-17-2014
So what isnt working?
# 5  
Old 06-17-2014
Code:
#!/bin/ksh
VAL=`ps -ef | grep -c swx | awk ‘{if ( $1 > 500 ) print $1 }’`
echo VAL=$VAL
read kyb # these 2 lines for testing purpose...
if [ "$VAL" -ge 500 ]  # "500" => string  does not match with -ge expecting numeric
then
   echo “$VAL user processes found running with SWX user. Exceeded the Threshold, \
   Please take immediate action.” | \
   /usr/bin/mailx -s “Alert !! $VAL SWX Application processes” email@test.com
fi
exit 0

Can you test by giving VAL different values and modifying if condition so it should send a post...
# 6  
Old 06-17-2014
I would like for modify that script to monitor when the Child process fails. What happens is that I have a parent process that starts and spawns different child processes. If one child process dies then the parent will continue to run but not correctly. I need to be notified if that child process fails

---------- Post updated at 08:35 AM ---------- Previous update was at 06:23 AM ----------

I wanted to clarify something. I realize that I can't reliably count on ps | grep or variants to accurately tell me what PID is started. However I know what I need for interim until this problem is resolved in the next release.

I have a process named Foo that is the parent, Bar is the child process. If Bar dies off Foo will continue to run and will not respawn Bar. How do I know this because the program to restart Bar requires Foo to be restarted first.

So when I want to monitor a child process it is just so I know to login and restart the parent process.

To make change to the ps command I was looking at
Code:
if pgrep "Bar" >/dev/null 2>&1
then
echo "Bar is running
else
echo "Bar is not running"
fi

or
Code:
if ps aux | grep "[B]ar" >/dev/null
then
echo "Bar is running"
else
echo "Bar is not running"
fi

The else portion will then fire off the sendmail to notify me.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

IBM eServer X 335 stops boot process at Server splash screen

Hi there. I used to use linux a lot a number of years ago but it has been quite a while so ?I really consider myself a beginner again. I have an old IBM eServer X Series 335 machine and I want to get it back up and running for a number of reasons. I knew that one of the SCSI drives was bad and... (2 Replies)
Discussion started by: filch2
2 Replies

2. Solaris

Clarifying sendmail configuration - sendmail-client offline

Hi all, I have read about sendmail running as 2 separate process. 1 as a MSP, and the other as the real daemon or MTA. In my current configuration, the sendmail-client is disabled. Both submit.cf and sendmail.cf are left as default untouch I do not specified any mailhost... (3 Replies)
Discussion started by: javanoob
3 Replies

3. Shell Programming and Scripting

Renaming directories stops resumption of write process

so lets say I have a process in cron that writes to a particular directory /var/tmp/EXAMPLEA so, from time to time, say every couple of months, an upgrade is made. and here's how the upgrade works: 1. move the existing directory /var/tmp/EXAMPLEA somewhere else and name it differently...i.e.... (6 Replies)
Discussion started by: SkySmart
6 Replies

4. Solaris

Nohup immediately stops.

I try and start a short script nohup the nohup immediately stops. Here's the code #!/bin/sh rm backup.out for i in `cat /home/xxxxx/Allservers.txt` do echo "Logging onto $i" ssh -qt $i '/usr/local/bin/sudo "/src/bkupsa"' done >>backup.out Any ideas? (3 Replies)
Discussion started by: ekrause77
3 Replies

5. Shell Programming and Scripting

Stops and start

Hi, I am not sure how well I can explain this.. Below is the file which I want to perform the code on.. Column 2 are my stop sites and column 3 are my start site.. For every gene I need to look at my starts(column3) and add +10,000 to it only if there is no gene when we move upstream 10,000(... (3 Replies)
Discussion started by: Diya123
3 Replies

6. UNIX for Dummies Questions & Answers

while loop stops after a function...

my ksh script is not working... i wanna remove lines in file2.txt from file1.txt # cat file1.txt this is line one this is line two this is line three this is line four this is line five # cat file2.txt this is line two this is line three # cat my_script.ksh #!/bin/ksh i=1 y=1... (8 Replies)
Discussion started by: curtis911
8 Replies

7. UNIX for Dummies Questions & Answers

Sendmail process "Toomany" system slowing down

Hello Experts I have M4000 Solaris 10 server, from few many days there are too many sendmail and mail.local process starting on server and each time i need to kill mannualy using pkill send mail, some time there will 600 of them taking 30mb memory for each and hence slowing down the server,... (2 Replies)
Discussion started by: karghum
2 Replies

8. Shell Programming and Scripting

ssh stops a while loop

The while loop exits (early) when a simple ssh command is run. #!/bin/ksh #set -x #------------------------------------------------------------------------- # Functions Section #------------------------------------------------------------------------- while : do cat list.txt|while read... (1 Reply)
Discussion started by: bkdias26
1 Replies

9. Solaris

ufsrestore stops

Hi, SUN E3500 box. boot cdrom -s create disk partitions mount on /a one of the partitions cd /a ufsrestore -rf dev/rmt/0n Starts create de inodes Starts the extraction and then...... stops the extraction without any error and didn´t extract all files and stays forever waiting for i... (1 Reply)
Discussion started by: spacewalker
1 Replies

10. AIX

LED stops at 406eoch6 help

Hi can anybody help me when i boot up my machine the LED runs until it gets to 406coch6 and it simply stops their noting appears on the screen...? Is their a website that lists all the codes and their meaning Thanks Liam (2 Replies)
Discussion started by: lodonovan
2 Replies
Login or Register to Ask a Question