perl script to monitor 2 processes


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting perl script to monitor 2 processes
# 1  
Old 12-16-2009
perl script to monitor 2 processes

I have two processes that I need to keep running. The first process is a server, the second is basically a canvas for creating images which get saved to a directory. So I plan on using launchd (Mac OS 10.5) on a server to check every minute or so to make sure two things are true:

1) Both apps are running.
2) Neither app is hanging (I can do this by checking the image directory to make sure time stamps of certain files aren't more than an hour old)

I also want to just reboot the whole thing once per day at midnight.

Last time I used perl was about 10 years ago so I really need some help. Here's what I'd like to do in a pseudo code format:

Code:
///////////////////////////////////////////////////////
// pseudo code

process A = "oc4j.jar" // server
process B = "Sentinel.app" // adobe AIR app which connects to server
imgDirectory = "imgDir"

boolean imagesCurrent = (loop through imgDirectory and check time stamps against current time)

if ((A or B) not running OR time == midnight OR !imagesCurrent) {
// attempt to shut down both
shut down A 
shut down B
}

if (A not running) {
launch A
wait 10 seconds for server to start up
launch B
}


Last edited by Scott; 12-16-2009 at 07:08 PM.. Reason: Pseudo code still looks better in real code tags
# 2  
Old 12-16-2009
I have something conceptually similar at Fork and exec with Perl

I think you could steal that and modify it for your needs.
# 3  
Old 12-17-2009
Thanks for the response. I'm afraid I did not have the necessary expertise to make sense of the linked article. So I am dropping perl and trying a bash script. Here's what I have so far. The killall command isn't working though. It gives me the error:

"No matching processes belonging to you were found"

I must have the file name (oc4j.jar) wrong? Not sure what's going on there.

Code:
#!/bin/bash

FILES="Development/oc4j/j2ee/home/applications/terracotta/terracotta/beta/Energy_and_Power_on_Target-img.png"

for f in "$FILES"; 

do 

if test `find $f -mmin +60`; then 
	echo "Old file needs to be shut down $f";
	killall *oc4j.jar;
  else 
	echo "File up to date $f";
  fi

done

sleep 7

PROCESS=oc4j.jar

if ps aux | grep "$PROCESS" | grep -v grep >/dev/null ; then
        echo Process $PROCESS is running
else
        echo Process $PROCESS is stopped  Restarting it ...
        java -jar Development/oc4j/j2ee/home/oc4j.jar
fi

# 4  
Old 12-19-2009
I believe that you have to do a killall on the process that is calling your jar file. You could cheat and do a ps aux | grep [o]c4j.jar | awk '{print $2}' to get the pid number and then just kill the pid.

(the [o]c4j.jar is a way to change the grep so you dont need the -v grep, as it is now a regex.)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Script monitor website wth default tomcat script

Hi all, on our application server we have the following script that monitor the status of the website, my problem here is that i have edite the retries from 3 to 5, and the timewait to 120 second, so the script should check 5 times every 2 minutes, and if the fifth check fails it must restart... (0 Replies)
Discussion started by: charli1
0 Replies

2. Infrastructure Monitoring

Searching for Saas Monitor service which monitor my servers which are sitting in different providers

Sorry if this is the wrong forum Searching for Saas Monitor service which monitor my servers which are sitting in different providers . This monitor tool will take as less CPU as possible , and will send info about the server to main Dashboard. The info I need is CPU / RAM / my servers status (... (1 Reply)
Discussion started by: umen
1 Replies

3. Linux

Linux Total Processes - Why monitor it?

Hi Guys, Monitoring 'Total Processes' on Linux servers has been always something you 'should' do. My question is - why? Is it relevant anymore? If you monitor memory and cpu params, you have a pretty good idea about what's going on. Is the number of processes really matter? Thanks (1 Reply)
Discussion started by: DjDeaf
1 Replies

4. Shell Programming and Scripting

Shell script executed from Informatica ETL tool is spawning 2 processes for one script

Hi, I am having a shell script which has a while loop as shown below. while do sleep 60 done I am executing this script from Informatica ETL tool command task from where we can execute UNIX commands/scripts. When i do that, i am seeing 2 processes getting started for one script... (2 Replies)
Discussion started by: chekusi
2 Replies

5. Shell Programming and Scripting

onstat -d chunks perl monitor

I have a file I need to monitor with a perl script with the following format. I need to send off a 0 if it is above 95 in the 5th colum and a 1 if it is below. Any help on a simple perl script would be great. 75424958 999975 983170 /dev/rmetrochunk00 98.32 760c2dd8 ... (3 Replies)
Discussion started by: jlaigo2
3 Replies

6. Shell Programming and Scripting

script to monitor different processes on different Unix servers

GM, Can you pls help how to write a script to monitor different processes on different unix servers and send the output to a /tmp/report file, earlier my boss asked me to write a script to monitor just one process running on different servers and send the output to a file so I wrote this exec... (0 Replies)
Discussion started by: baders
0 Replies

7. Shell Programming and Scripting

Writing a Perl Script that processes multiple files

I want to write a Perl script that manipulates multiple files. In the directory, I have files 250.*chr$.ped where * is from 1 to 1000 and $ is from 1-22 for a total of 22 x 10,000 = 22,000 files. I want to write a script that only manipulates files 250.1chr*.ped where * is from 1 to 22.... (10 Replies)
Discussion started by: evelibertine
10 Replies

8. Ubuntu

How to monitor firefox processes?

Hi Team, I have over 100 users,working on LINUX machine & all they use firefox. I want to monitor traffic from every IP and mainly CPU USAGE TAKEN BY FIREFOX PROCESSES ON EACH MACHINE. Is there any tool which runs on lunux and will help me to monitor firefox processes of our entire LAN? ... (2 Replies)
Discussion started by: paragnehete
2 Replies

9. Infrastructure Monitoring

Using SNMP to monitor remote processes and disk space

snmpget -v 1 -c COMMUNITYSTR hostname OID what OIDs would I use to get information on all the processes and disk space information that are on a particular host. where can i find out information on all of this? thanks (3 Replies)
Discussion started by: SkySmart
3 Replies

10. AIX

how to monitor deamon processes

we have several deamon processes which were killed for some unknown reasons. we have to bring the deamon back manually everytime. Deamons running on 2 identical instances. It is ok on one instance but be killed 3 or 4 times a day on another. Any idea how to monitor it? like who/how the processes be... (3 Replies)
Discussion started by: hamiltonhall
3 Replies
Login or Register to Ask a Question