Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Listing all cron related processes 1

Status
Not open for further replies.

Chig

Technical User
Jun 4, 2002
1
GB
I want to list the processes spawned by cron from within a shell script. The following writes the current cron PID to a file.
ps -ef | grep -v grep | grep cron | awk '{print $2}' > $CRON

How can I then grep for the PID contained in the file?

Thanks,
 
I think that $2 is the TT and not the PID


``The wise man doesn't give the right answers,
he poses the right questions.''
TIMTOWTDI
 
No need for a temp file...

cronpid=$(ps -ef | grep -v grep | grep cron | awk '{print $2}')
ps -ef | awk '{if ($3=='${cronpid}') print}'

Notice that the awk quoted program is "interrupted" after the "==" of the if test and continued at the ")" of the if test in order for the shell to substitute the variable cronpid...

You have to find out which ps fields contain the parent process id, on AIX it is the 3rd one on a ps -ef listing, so I check for $3 in awk.

HTH,

p5wizard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top