Operating System - HP-UX
1834434 Members
2212 Online
110067 Solutions
New Discussion

Re: finding out process id of job submitted by at command

 
rakesh kumar jain_1
Occasional Advisor

finding out process id of job submitted by at command

Hello all,
I want to kill a looping job which was started by at command. How to find out
pid for the job. ps -ef does not show a job which matches with the submitted job's script name to find out it's process id eg a job has been submitted using following command:

at -f /scripts/myjob.sh now

it prints message similar to following:

job 1185957711.a at Wed Aug 1 11:41:51 2007

but I can not find out pid for running job.

Kindly suggest. Thanking you. RAKESH
14 REPLIES 14
Ralph Grothe
Honored Contributor

Re: finding out process id of job submitted by at command

Hi Rakesh,

since you now when you started the at job and since it is still running, you can easily retrieve the PID of the parent by looking into /var/adm/cron/log

Once you have "parsed" it from there you can look up your proc table by parsing all those procs whose PPID is identical to the PID in the cron log.
If those in turn have spawned other procs themselves it could be a bit nested and maybe the hierarchy switch of XPG4 ps would help (e.g. UNIX95= ps -H ...)
Madness, thy name is system administration
Ralph Grothe
Honored Contributor

Re: finding out process id of job submitted by at command

Hi Rakesh,

since you know when you started the at job and since it is still running, you can easily retrieve the PID of the parent by looking into /var/adm/cron/log

Once you have "parsed" it from there you can look up your proc table by parsing all those procs whose PPID is identical to the PID in the cron log.
If those in turn have spawned other procs themselves it could be a bit nested and maybe the hierarchy switch of XPG4 ps would help (e.g. UNIX95= ps -H ...)
Madness, thy name is system administration
Ralph Grothe
Honored Contributor

Re: finding out process id of job submitted by at command

Sorry, for the double posting.
Must have accidentally resubmitted.
Madness, thy name is system administration
rakesh kumar jain_1
Occasional Advisor

Re: finding out process id of job submitted by at command

Dear Ralph,

Thanks for your reply. It helped in finding out the process IDs of the jobs submitted by
at command.

I am executing the following script at command:

#!/bin/sh
mm=0
while test $mm -le 600
do
date >> /tmp/dbc6.log
ps -ef | grep dbcheck | grep -v grep >> /tmp/dbc6.log
mm=$mm+1
sleep 60
done
mailx -s "DBCHECK LOG" rakesh@kuc01.kuniv.edu.kw < /tmp/dbc6.log
#


But /tmp/dbc6.log file does not contain the output of ps command while executing after submitting by at command.

If I execute the script directly from my terminal, the output from ps -ef command
goes to /tmp/dbc6.log.

Why it is so & what can be done to get the
output in this file after submitting script through at command?

Thanking you once again.
Best regards, RAKESH
Bill Hassell
Honored Contributor

Re: finding out process id of job submitted by at command

Your script can be modified for much better reliability like this:


#!/bin/sh
mm=0
while test $mm -le 600
do
date >> /tmp/dbc6.log
INIX95=1 ps -f -C dbcheck >> /tmp/dbc6.log
let mm=$mm+1
sleep 60
done
mailx -s "DBCHECK LOG" rakesh@kuc01.kuniv.edu.kw < /tmp/dbc6.log



The arithmetic statement: mm=$mm+1 requires one of these formats:

let mm=$mm+1
mm=$(($mm + 1))
mm=$(expr $mm + 1)

The statement in your original script: mm=$mm+1 produces:

echo $mm
0+1

and not the next higher number. The use of ps -C eliminates numerous errors in selecting processes because they have your search string imbedded somewhere. ps -C is 100% reliable as it looks at the process table rather than grep.


Bill Hassell, sysadmin
Bill Hassell
Honored Contributor

Re: finding out process id of job submitted by at command

Oops, keyboard error...the ps line should be:

UNIX95=1 ps -f -C dbcheck >> /tmp/dbc6.log

The man page explains the special options -C -H -o (and others) that are activated in the XPG3 environment, designated by the temporary use of the UNIX95 variable.


Bill Hassell, sysadmin
Ralph Grothe
Honored Contributor

Re: finding out process id of job submitted by at command

Are you sure your loop counter var mm gets incremented.
Maybe in your current shell, where things work, you have already declared it as integer?

In the script I would suggest

typeset -i mm=0
...
((m+=1)) # instead of mm=$mm+1

Also note, that cron as well as at and batch jobs are executed with a minimalistic environment that might deviate considerably from the one in your current shell.



Madness, thy name is system administration
Ralph Grothe
Honored Contributor

Re: finding out process id of job submitted by at command

Sorry, for my redundant information.
Bill must have posted while I was still filling in the form's textarea.
Madness, thy name is system administration
rakesh kumar jain_1
Occasional Advisor

Re: finding out process id of job submitted by at command

Thanks for the suggestions for incrementing
mm variable. I will check it more carefully by displaying the value of mm after inrementing it.

The main reason for asking the question was
that when I execute the :

ps -ef | grep dbcheck | grep -v grep >> /tmp/dbc6.log

Command (kindly consider the second line also as first line ... while writing this it automatically is wrapping it to second
line here) does not produce any output in
/tmp/dbc6.log file when the procedure is executed using at command but it produces the proper output if same script is execued
on terminal directly. What is the reason for this & how to handle the situation to
get the output in the file after executing
the script using at command?

Thanking you once again.

Best regards, RAKESH
Dennis Handly
Acclaimed Contributor

Re: finding out process id of job submitted by at command

>Ralph: Also note, that cron as well as at and batch jobs are executed with a minimalistic environment

This is incorrect. at(1) and batch(1) jobs are invoked with your current environment, umask and directory.

They don't have aliases or functions. Of course scripts should be using any of these that are not defined explictly.

>Command does not produce any output in

Since your environment should be available in at(1) jobs, a wrong PATH doesn't explain it.
But it wouldn't hurt to use this to check:
whence ps
whence grep

Also, have you used Bill's suggestion for the ps(1) command?

>Ralph: Sorry, for my redundant information.

Don't be. Your ((m+=1)) solution was better than Bill's. ;-)
Ralph Grothe
Honored Contributor

Re: finding out process id of job submitted by at command

I have to apologize for giving false testimony in saying nonsense about "at" or "batch" jobs' environments by prematurely deducing from cronjobs.
Of course is Dennis correct, which in this case I even could have verified without any reference to the man page by simply issueing

# at -d .a

As for your proc tab grep issue,
have you tried to use the XPG4 -C option that Bill suggested and discarding all the obsolete "grep -v grep" stuff?
If the command's base name without any args really is "dbcheck" then a "UNIX95= ps -C dbcheck" should produce valid output.
Since I don't have this proc on my box lets take another ubiquitious proc as example:

$ UNIX95= ps -C httpd -o pid,ppid,args
PID PPID COMMAND
2104 1 /opt/hpws/apache/bin/httpd -d /opt/hpws/apache -k start
2106 2104 /opt/hpws/apache/bin/httpd -d /opt/hpws/apache -k start
2115 2104 /opt/hpws/apache/bin/httpd -d /opt/hpws/apache -k start
2113 2104 /opt/hpws/apache/bin/httpd -d /opt/hpws/apache -k start

As you can see, it doesn't even matter what bunch of args is following.
The -C option is a really fail-safe as opposed to obsolete ps grep chicanery.



Madness, thy name is system administration
OldSchool
Honored Contributor

Re: finding out process id of job submitted by at command

you might also consider modifying your script to do:

echo $$ > /.pid

which should place the script's current process id in the file.
rakesh kumar jain_1
Occasional Advisor

Re: finding out process id of job submitted by at command

Dear All,

Thanks for replies. These have been very useful. Now I know how to find process Id for a job submitted through at command &
also how to save its own pid in a file for
a process. Also, there was a mistake in my
script for adding 1 to a variable for which
various useful suggestions were provided. I checked one of my old scripts where I was
using:

mm=`expr $mm + 1`

I used this now & it works fine.

My actual problem was that some process was
executing dbcheck program (used for Data
Protector's Internal DB) & I was unable to
figure out which program it could be. With some more modifications to my script I managed to find out that HP Openview Operations (OVO) does this. This is causing the failure of backing up DP's Internal DB.
Anyway, now we know who is causing the problem so now we can take proper action.

Thanking you all once again.

Best regards, RAKESH
rakesh kumar jain_1
Occasional Advisor

Re: finding out process id of job submitted by at command

1. How to find process ID of a job submitted
through at command.
2. Some new fags (eg UNIX95) available.

3. Various ways of incrementing counter
a counter variable.