Comparing CRON PID w/Current PPID


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Comparing CRON PID w/Current PPID
# 1  
Old 05-08-2008
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. Smilie 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  
Old 05-08-2008
What is problem you have with it. Try to echo the variables to see if you get the proper pid and ppid.

Regards
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. HP-UX

Comparing the timestamp of the file to current time

I have a file like this -rwxr-xr-x 1 rewq other 168 Jan 13 07:05 check_files.sh I want to compare (check_files.sh time) with the current time to see if its is older than 2 hours or not if it is not older than 2 hrs then do something.can someone help me on this?.I dont... (7 Replies)
Discussion started by: haadiya
7 Replies

2. AIX

Cron jobs with same pid

Hello, I have an AIX6.1 machine and i noticed something "strange" in the server. I noticed that each day there are times where 2 or 3 different cron jobs are running with same process id. How can this happen? I thought that pid is always unique for each process. Is it a problem having this... (4 Replies)
Discussion started by: omonoiatis9
4 Replies

3. UNIX for Dummies Questions & Answers

Comparing two files with datestamp to current date

Hi, I am new to unix and I am stuck on how to compare two .zip file with date stamp in my directory. I need to compare out of the two file which is oldest to current date and unzip it after that done continue to unzip the second zip file. Thanks for your help. (5 Replies)
Discussion started by: lilvi3tboix1
5 Replies

4. UNIX for Dummies Questions & Answers

PID and PPID - please explain :(-

Hi, I need some help understanding PID and PPID that is shown by the ps -ef output. OS is Solaris 5.8. :wall: There are several Oracle databases and processes running on this server and they all have the same PPID. Does that mean they are all spawned off the same startup script? I then... (1 Reply)
Discussion started by: newbie_01
1 Replies

5. UNIX for Advanced & Expert Users

how to display pid and other parameters of current process through kernel module ?

how to display pid and other parameters of current process in linux platform ? i know it can be done through a linux commmand ps -F but i want it done through kernel program thanks in advance (1 Reply)
Discussion started by: vaibhavkorde
1 Replies

6. Shell Programming and Scripting

Comparing current date

Hi, I have start date and end date in the following format. I need to check the current date is greater than the start date and less than the end date. if i use the command date --date "Tue 6:00 AM", it takes next Tues day not the current week's Tues day. Is there a way to get the current Tues... (9 Replies)
Discussion started by: bharathappriyan
9 Replies

7. UNIX for Dummies Questions & Answers

comparing field to current year

Hi, I have a comma delimited file that contains name, account number, and account date/time(example record below). I want to pull off all the records that have an account date greater than 8/1 of the current year, and create a new file with those records. So for this year, it would take... (6 Replies)
Discussion started by: keeferb
6 Replies

8. Shell Programming and Scripting

comparing PID values of 2 Files in shell Options

Hi, There is a file having a list of running PIDs and another file having a list of registered PIDs. How can we check if each value of running PIDs are less or more than the registered PIDs i.e. comparing the value of each PID in both the files. Request you to pls give your inputs. ... (2 Replies)
Discussion started by: marconi
2 Replies

9. UNIX for Advanced & Expert Users

strange pid and ppid problem

Hi all, Please look into the following code : int main() { char command; int pid, ppid; ppid = getpid(); /* Get the parent pid */ pid = fork(); /* Fork */ if ( pid ==0 ) { sprintf( command, " gdb a.out %d ", ppid ); printf( "Command line is %s\n", command ); system( command... (3 Replies)
Discussion started by: asvija
3 Replies

10. Programming

printing ppid,child pid,pid

question: for the below program i just printed the value for pid, child pid and parent pid why does it give me 6 values? i assume ppid is 28086 but can't figure out why there are 5 values printed instead of just two! can someone comment on that! #include<stdio.h> #define DIM 8 int... (3 Replies)
Discussion started by: a25khan
3 Replies
Login or Register to Ask a Question