Problem with executing a shell script through the cron


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem with executing a shell script through the cron
# 1  
Old 06-04-2010
Problem with executing a shell script through the cron

Hi,

I have a shell script as below:

ORACLE_HOME=/usr/local/opt/oracle/product/dev
export ORACLE_HOME
PATH=$PATH:$ORACLE_HOME/bin:/usr/bin
export PATH

OUTFILE=/export/home/`basename $0`.out
export OUTFILE
export IDEN

df -k . | tail -1 | read a b c d e f
echo $a >> $OUTFILE
echo $b >> $OUTFILE
echo $c >> $OUTFILE
echo $d >> $OUTFILE
echo $e >> $OUTFILE
echo $f >> $OUTFILE

When i try to execute this script manually, I get the value for all a,b,c,d,e,f populated. However, on trying to execute it thru the cron, all these values come blank.

Can anyone help me with the reason behind this?

Thanks in advance.
# 2  
Old 06-04-2010
cron's default PATH is much more barebones than one you get from a login. Set PATH to a sane default, not just $PATH:otherstuff

Also, this:

Code:
df -k . | tail -1 | read a b c d e f

I'm amazed this ever worked. You must have been using a very strange shell to get those variables read and assigned in a usable way behind three pipes. In nearly every shell that'd be done in a subshell, and save no results to the main shell. Redirect the output of that into a tempfile instead, and read a b c d e f < tempfile, then rm -f tempfile
# 3  
Old 06-04-2010
That will only work in ksh88 or ksh93; cron jobs are run by /bin/sh unless otherwise specified.
# 4  
Old 06-04-2010
So you tell everything, env is not same as you login. Define the shell, PATH and so on.
Ksh can read from pipe, no problem.
Code:
#!/usr/ksh
PATH=/bin:/usr/bin:...
...

# 5  
Old 06-04-2010
This syntax has always worked for me in SunOS ksh.

In my cron jobs, I always have a special cron_env.sh that contains all of my required variables like PATH and whatnot. Then the cron entry looks something like:

Code:
* * * * * /bin/ksh /home/quirk/bin/cron_env.sh /fullpath/to/my/cron_job.sh

... keeping all complicated looking garbage in the cron_job.sh itself.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Script is not executing as expected when I schedule it in cron

Hi, I have a shell script which fetches the MRP status and the LAG status. When I execute it manually like, sh <script_name>, it fetches the output as expected, but when I schedule through crontab, it's not working as expected. Any help would be really appreciated. Here is the code... (3 Replies)
Discussion started by: Nagaraj R
3 Replies

2. Shell Programming and Scripting

Expect script not executing via cron

Hello All, I'm having an issue getting an expect script to run as a cron job. The script executes fin if I run it from the command line but I get nothing when trying to run it as a cron job. I've researched other forums and threads and there have been references to the environment, or lack... (16 Replies)
Discussion started by: KingT617
16 Replies

3. Shell Programming and Scripting

Script not executing using cron

Hi, I created a script which connects to database and update a table. This script is running fine when i run it manually but when i am trying to execute it scheduling in crontab.script is executing but Data is not getting updated. below is my script sqlplus test/##### >> test_feed.log <<!... (6 Replies)
Discussion started by: sv0081493
6 Replies

4. UNIX for Dummies Questions & Answers

Cron shell script not executing diskutil command

I'm trying to learn how to use cron for repetative tasks. I have an external disk that needs to be unmounted and remounted every hour due to some problems that a backup utility (specifically, TimeMachine) is having repeatedly accessing the device. I've created a shell script that will find the... (3 Replies)
Discussion started by: illuminate
3 Replies

5. Shell Programming and Scripting

Executing a script from CRON behaves differently than terminal

Hi have a script which transferers from Microsoft server to Linux box. The scripts(ksh) is on Linux box. If I run script from terminal, it transfers files to directory. Where as If I run script from CRON. It does not. Here is the log of both: Terminal execution log:... (2 Replies)
Discussion started by: dipeshvshah
2 Replies

6. Shell Programming and Scripting

Problem Executing Firmware Command using Shell Script

Guys, I have a script that should change one of the configuration Parameter in a http accelerator, this config change which will halt http traffic into device. So I have designed a script which should do these changes. But after executing this script, found that one of the input variable is not... (8 Replies)
Discussion started by: raghunsi
8 Replies

7. UNIX for Dummies Questions & Answers

Problem with executing command inside a cron job

Hi All, I have scheduled a script in cron which writes output to the below file. ....>> /data/Target/wrapper_invoke_ds_job_`date '+%Y%m%d'`.ksh_out 2>&1 But the date command is not getting resolved in the format specified. It just resolves to the following. wrapper_invoke_MQ_ds_job_Tue... (3 Replies)
Discussion started by: pkm_oec
3 Replies

8. AIX

Having problem with executing shell script to get the pid details!

Hello Everyone, I am new to shell scripting and also i am very new to AIX machine I have a question. I have shell script which contains the follwing "ps -e |grep $1 echo $2" i run this schell script by doing this ./startSehllscript 3444 passed with two parameters . Accroiding my... (4 Replies)
Discussion started by: swati
4 Replies

9. UNIX for Dummies Questions & Answers

Problem with scheduling a shell script on cygwin using cron

Hi, Before I start, I would like to inform that, I went through all FAQs and other threads before posting here. I 'm trying to schedule a shell script on cygwin using cron. No matter what I do I don't seem to get the cron job executing my bash script. My script is temp.sh echo `date` >... (4 Replies)
Discussion started by: shash
4 Replies

10. HP-UX

executing shell script from the cron

This isn't the usual problem that a shell script runs from the command line and not the cron. It's a little different. Among other things, the shell scrip executes my .profile to set a bunch of variables. It then does an env to ensure that it ran OK. There are echos in the shell script and... (2 Replies)
Discussion started by: abNORMal
2 Replies
Login or Register to Ask a Question