The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Install a cron from a Perl script garric Shell Programming and Scripting 2 09-13-2007 02:00 AM
Cron job for Perl script man UNIX for Advanced & Expert Users 3 07-26-2007 10:20 AM
How to determine the script is called from CRON? wes_brooks Shell Programming and Scripting 15 09-10-2005 09:04 AM
script to go to a different dir to run a commandline prompt in that dir ann_124 Shell Programming and Scripting 2 11-29-2004 10:25 AM
gzip in shell script called by cron hbau419 Shell Programming and Scripting 2 02-05-2002 03:03 PM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-22-2006
Registered User
 

Join Date: Mar 2006
Posts: 1
How to determine if a script (perl) was called from a CRON job or commandline

Hi,

Is there a way to determine if a Script is called from a
CRON job or from a commandline

Gerry.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 03-22-2006
Registered User
 

Join Date: Jul 2005
Location: Mt. Prospect, Illinois
Posts: 32
Report from cron vs. command line

cron is pretty good about reporting to the user its status, i.e. whether it's running / active. If you're suspicious, then I would suggest placing an echo
statement (1.) in the/(a) cron script and noting its affect. I suggest you have a look at the man page for cron as well.

1. echo "This output has been created by cron..."

Good luck!
Reply With Quote
  #3 (permalink)  
Old 03-23-2006
Registered User
 

Join Date: Mar 2006
Location: South Yorkshire, UK
Posts: 114
If your UNIX maintains a PPID variable in the environment then this will point to cron:

# echo $PPID
86838
# ps -fp 23266
UID PID PPID C STIME TTY TIME CMD
root 23266 1 0 03 Jan - 1:37 /usr/sbin/cron

If not then (a lot looser), you could look at the TERM variable. THis is usually 'dumb' for cron whereas users will have a real terminal type; like vt220, wy50 etc.

cheers
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 10:51 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0