Manual vs Cron execution in HP-UX


 
Thread Tools Search this Thread
Operating Systems HP-UX Manual vs Cron execution in HP-UX
# 1  
Old 06-02-2010
Manual vs Cron execution in HP-UX

Below is a simple script that will find the path were the perl command reside.
=========================
Code:
#!/usr/bin/sh

nPerl=`which perl 2>>/dev/null|grep -v "no perl"`
if [ -z "${nPerl}" ]; then
echo "No Perl application exist..."
else
echo "Existing at $nPerl"
fi

=========================

When I execute this manually, it can find the correct path (/usr/contrib/bin/perl). But if I put it in cron, the value of nPerl is empty. The value returned by "which perl" is "no perl in /usr/bin /usr/sbin ."

Need your expert advise how I will resolve this problem. I haven't encounter any problem with Linux, AIX and Solaris when I execute this via cron.

Last edited by vbe; 06-02-2010 at 09:36 AM.. Reason: use code tags
This User Gave Thanks to padi For This Post:
# 2  
Old 06-02-2010
The PATH variable is not set, the default PATH for cron jobs is:
"/usr/bin:/usr/sbin"

You will have to source /etc/profile or whatever script defines the PATH.
# 3  
Old 06-03-2010
Hi Jim,

Based on your advise, I copied the PATH contained in the /etc/profile and pasted it in the script and it worked fine.

Is there another way of doing it instead of pasting the path in the script since I will deploy the script in several unix/linux servers and I don't want to hard code it? I can imbed in the script to grep the PATH in the /etc/profile but maybe there's another way of implementing it. Thanks.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Execution problem with Cron

Hi, I'm unable to understand why the grep command in cronjob works intermittently Expected output: Grep command to look for a particular string with today's date and exit from infinite while loop else it must sleep for 5 mins I'm using the following statement in my shell script, the... (9 Replies)
Discussion started by: charlie87
9 Replies

2. UNIX for Dummies Questions & Answers

Execution problem with Cron: Script works manually but not w/Cron. Why?

Hello gurus, I am making what I think is a simple db2 call from within a shell script but I am having difficulty producing the desired report when I run the script shown below from a shell script in cron. For example, my script and the crontab file setup is shown below: #!/bin/ksh db2... (3 Replies)
Discussion started by: okonita
3 Replies

3. Shell Programming and Scripting

How to check if script is run via cron or manual=command line?

Hi all, I have a script that can be run via cron or via the command line. Is there any way that I can place something on the script to be able to distinguish/differentiate whether the script was run via a user in the command line or whether it was run from the cron? (3 Replies)
Discussion started by: newbie_01
3 Replies

4. UNIX for Dummies Questions & Answers

Execution Problems with Cron

Hi friends, today i created a cron job , registered the crontab file associated but dont know why the cron is not getting executed at the right time.?? content of Crontab file : 21 15 * * * /subrat/myt i wanted to execute the script myt on 15:21 PM of everyday. the script myt... (2 Replies)
Discussion started by: paras.oriental
2 Replies

5. Shell Programming and Scripting

Execution Problems with Cron

Hi, I have written a shell script to transfer files to a SFTP server passing the filername, source and dest directory as parameters and it runs well. :) I want to schedule this script to run periodically using a cron job. root@pingu # cat /etc/crontab SHELL=/bin/bash... (1 Reply)
Discussion started by: chetancrsp18
1 Replies

6. Programming

execution problems with cron

how to store a date into file? and how we can access date from the file? ---------- Post updated at 06:09 AM ---------- Previous update was at 06:08 AM ---------- how we can store date in file? (1 Reply)
Discussion started by: causalmodi777
1 Replies

7. Shell Programming and Scripting

Execution on cron does not work well

Hallo everyone, this is my first post here and I hope i will learn a lot from you guys. I have the following command that somehow only works interactively, when I put the the following to the cron, it does not work. It suppose to move file from one folder to another folder that's all. ... (7 Replies)
Discussion started by: msetjadi
7 Replies

8. Solaris

cron execution

Hi, Here is the code snippet when executing on the command line it does execute smoothly, but while i place this on cron it doesnt run. Can anybody suggest where the problem in cron is.? #!/usr/bin/ksh home_dir="/export/home/scripts/MonitorScripts" ThresholdLimit=5 touch... (6 Replies)
Discussion started by: rameek20
6 Replies

9. Shell Programming and Scripting

script execute by cron problem, but manual ok

Hi; I'm facing the problem with my script like below 30 0 * * * /data/SCRIPT/LOADLOGS/loadata1.sh 2 1 >> /tmp/loaddata.txt loadata1.sh calling a another 2 scripts which we need to exe in sequence. when it perform by cron jon, sometimes it just can process 20 recs or less or nothing but... (6 Replies)
Discussion started by: izai
6 Replies

10. HP-UX

Cron Skips Execution

Hi All, I got a very strange problem, i have created a cron schedule that will run a programme once in every 12 mins, like 04,16,28,40,52 * * * * /myf/startProcessA 1> &- Some time the cron skips the execution such as 04,28 instead of executing at 16 mins. it starts execution at 28, i... (6 Replies)
Discussion started by: nag_sundaram
6 Replies
Login or Register to Ask a Question