How to determine if a script (perl) was called from a CRON job or commandline


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to determine if a script (perl) was called from a CRON job or commandline
# 1  
Old 03-22-2006
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.
# 2  
Old 03-22-2006
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!
Smilie
# 3  
Old 03-23-2006
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script executed by Cron or commandline

Hello all, I have a question regarding the difference betwen cron and command line. What I would like to do is to print a statement into a logfile if a script has been executed from cron or from command line. It should be as: #!/bin/bash if <Check if this script has been... (3 Replies)
Discussion started by: API
3 Replies

2. Shell Programming and Scripting

Shell script not getting called through cron job but executes fine manually.

Hi, My shell script not getting called through cron job. The same works fine when executed manually. I tried to generate logs to find if the scripts has some errors related to path using following command- trying to execute .sh file every 5 mins: */5 * * * * /home/myfolder/abc.sh... (17 Replies)
Discussion started by: Dejavu20
17 Replies

3. UNIX for Dummies Questions & Answers

Interpreting Shell Script errors when called from CRON

Hi All, I am calling a series of shell scripts via CRON so everything is running as root. However, in my error log file I am seeing the following errors. Please can anyone offer any advise as to the possible causes and solution to prevent the errors from appearing. The Error 1227 seems to... (2 Replies)
Discussion started by: daveu7
2 Replies

4. Shell Programming and Scripting

get system date, format it, pass it as a parameter to a perl script - all in cron job

I am trying to get the string containing date - in a specfic format actually, although I think that part is inconsequencial - 1110226^1110226^1110226^1110226^1110226 - through echo or printf or in some other way - created within a cront job and passed as a parameter to a perl script. Now, I know... (3 Replies)
Discussion started by: v8625
3 Replies

5. Shell Programming and Scripting

Script not working when called by cron

Hello, I have the following script which works fine when ran from the command line: #!/apps/python/2.3.4/bin/python import os import sys import time user = os.getenv("USER") string = time.strftime("%m%d%y0000 " + user, time.gmtime()) However, when I have this run by crontab, I... (4 Replies)
Discussion started by: cooldude
4 Replies

6. Shell Programming and Scripting

autosys job name in the called script

Hi, i have an autosys job 'AUTJOBA' that calls a script script1.sh Now, inside the script i would like to know the autosys job that kicked off this script. When AUTJOBA runs script1.sh, will it set an environmental variable for this shell session that can be accessed within this script? ... (1 Reply)
Discussion started by: ysrinu
1 Replies

7. UNIX for Dummies Questions & Answers

a cron job needs a perl script to execute

Hello evreyone, this is my first post, and to say i'm new to this is an understatement. I know very little about perl scripts and hope some one can help me. i'm looking to get a script that a cron job can execute. what the script needs to to is 1) connect to a mysql database 2) go to a... (2 Replies)
Discussion started by: Exader
2 Replies

8. UNIX for Advanced & Expert Users

Cron job for Perl script

Although there are many threads on this forum regarding cron, none have specifically answered my question. So hopefully someone can shed some light on what I'm doing wrong.. I have a perl script that I want to run in a cron job. Since I've read that cron doesn't have any environments set, I... (3 Replies)
Discussion started by: man
3 Replies

9. Shell Programming and Scripting

How to determine the script is called from CRON?

Hello expert, What I want is to determine whether the script is called from CRON or it is executed interactively? I tried the following but no luck: #!/bin/ksh cronID=`pgrep -x cron` GPID=`ps -ef -o ppid,pid | grep " $PPID$" | awk '{print $1}'` if ; then echo I am being run... (15 Replies)
Discussion started by: wes_brooks
15 Replies

10. Shell Programming and Scripting

gzip in shell script called by cron

I'm puzzled by this one. I hope you can explain it to me. I have a ksh shell script that gzips a file among other things. This works perfectly fine when the script is manually run through a shell. However, when the same script is run through cron, it does everything correctly, but it will... (2 Replies)
Discussion started by: hbau419
2 Replies
Login or Register to Ask a Question