The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Perl: Extracting date from file name and comparing with current date MKNENI Shell Programming and Scripting 4 03-26-2008 04:01 PM
what is the meaning of ppid 1? darkrainbow UNIX for Dummies Questions & Answers 2 08-02-2007 10:56 AM
Need a script to kill processes with PPID of 1 lbaysdon Shell Programming and Scripting 5 04-13-2005 01:01 PM
strange pid and ppid problem asvija UNIX for Advanced & Expert Users 3 03-10-2005 11:34 PM
printing ppid,child pid,pid a25khan High Level Programming 3 02-02-2004 01:13 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-08-2008
GregWold GregWold is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 11
Question Comparing CRON PID w/Current PPID

All,

I've got a script that needs to check if it was started by cron. The code seems to be right, but it's not running correctly if cron starts it. Am I getting the pid's correctly? I'm not having any luck figuring it out. Any help is appreciated!


Code:
      CRON_ID=$(ps -aef | grep /usr/sbin/cron | grep -v grep | awk '{print $2}')
      CP_ID=$(ps -aef | grep $PPID | grep -v root | grep -v grep | awk '{print $3}')

      if test $CRON_ID = $CP_ID
      then
         # cron started the script
      else
         # user started the script

  #2 (permalink)  
Old 05-08-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,345
What is problem you have with it. Try to echo the variables to see if you get the proper pid and ppid.

Regards
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:42 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0