How to log start/stop time of ALL processes

Hi all,

I joined this forum today and this is my first question. I thank you all for viewing it. I will try to be brief.

The OS: HP-UX B.11.11 U 9000/800

There are lot of cron scheduled perl scripts running on this server, which do different things at different time. Some of them process incoming csv files (from some server), some scripts upload that data to a oracle DB, some anther scripts process that data and populate some other table and so on. I am sorry if this is confusing, but there are more than 300 scripts running (at different time per day). They can run for 10 seconds or 3 days.

Now my problem:

My boss wants to monitor all scripts' start-stop time in real time. Something like this

Script name----Start date---Start time---Stop date---Stop Time
Script1 mm/dd/yyyy hh:mm:ss mm/dd/yyyy hh:mm:ss
....

(I need to do this for 3 different logins, which have different perl scripts scheduled).

Is there any way (without manually running PS command for each script) so that the start and stop time of all these scripts will be logged automatically?

I am sorry if I have broken any rule of this forum by putting this in wrong thread. I appreciate any input from all of you Unix Gurus.

In the way you've described it :

I can think of only one possible way - putting such lines to be executed in the beginning and at the end of each script, like :

#!/bin/bash 
echo "$0 start date=`date`" >> some log file

the script content goes here.....and

echo "$0 end date=`date`" >> some log file

This will require manual editing all of your scripts, which, may not be written in the same language, thus creating additional obstacles. Other disadvantage is that maintaining such log file will be sort of "not-well-arranged" because random scripts will write lines of info at pretty much random times, i.e. such file may look like :

which won't be very readable. That's what I can produce on prima vista, I'll be glad to hear other opinions and solutions.

Is there a cron log in /var/adm/cron?

Thanks sysgate and prowla for your replies.

Sysgate- you are right, modifying every perl script is not possible. The scripts were written 5 to 10 years back, and probably the debugging options were not on their priority list. I was affraid that I might not have any other option than modifying each script.

prowla- That is excellent! The log file is there, and seems to contain useful information. Now I need to worry about parsing that file and generating some useful reports! I will try to write a simple shell or perl script which can list ALL processes for a certain user, for a specific time period. One problem I can foresee is that it may not contain the stop time - any ideas on that?

I will keep you posted guys, Thanks for your support and spending time on this. :slight_smile:

However there is nothing to stop you using a wrapper script which does the timing and calls the original script.

Thanks porter, but there are hundreds of scripts running, and they are either Ksh or Perl scripts. Do you mean a separate wrapper for every script? A common wrapper is not possible, since I am not supposed to modify cron entry.

A common wrapper should be the way as writing a wrapper for 'n' number of scripts is not an ideal way

How about something like,

* * * * 1 common_wrapper.sh && yourscript.ksh && common_wrapper.sh

Thanks matrixmadhan. I could try that, but as I said before, I am not allowed to modify the cron entry (It's not my company's constratint, but imposed by our client). I know probably there is no way to do this, but is there anything which logs all processes start-stop time?

One last hope - If I have the process id of any process that has exited normally (or abnormally, whatever), can I get the time when it finished?

if cron mails the output then the time/date of when the script finished will be in the mail. Is this the case with HP UX?

Thanks wempy.
The HP-UX man page says:

Be sure to redirect the standard output and standard error from commands. If this is not done, any enerated standard output or standard error is mailed to the user.

Cuerrently the output of all scripts is directed to various log files. They do not contain time and date stamp. Just the output from the script ("Connected to DB", "Processing record nnnn" and so on)

If the log file to which debug messages and error messages are redirected donot contain time - stamping information ( it should have been time stamped debug message ) I think there is no way to retrieve the start and end time.

As far as I know, once the process is exited or terminated abnormally start and stop information of the process is not stored in process table entry as the process is a clean - no more existing