0

I'm trying to execute a shell with crontab. The cron job executes the shell but doesn't generate the log file i need.

This is what i'm using for my cron: 10 * * * * /home/user/3nvo.sh

This is a simple shell that has the same structure:

#! /bin/bash

export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/MCMMX
export OH=$ORACLE_HOME
export SHLIB_PATH=$ORACLE_HOME/lib:/usr/lib/Motif1.2
export ORACLE_SID=MCMMX
export ORA_NLS33=$ORACLE_HOME/ocommon/nls/admin/data
export TMPDIR=/tmp
export DESA_HOME=/home/manager
LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib; export LD_LIBRARY_PATH
export FECHA=`date +"%d-%m-20%y_%H:%M:%S"`
PATH=$PATH:.:/opt/bin:$ORACLE_HOME/bin:/bin:/usr/bin:/usr/ccs/bin:/usr/sbin:/opt/perl:/opt/p    erl/bin:/usr/kerberos/bin
ERROR="error_carga_nextone_$FECHA.log"
WARNING="warning_$FECHA.log"
DUMMY="dummy.txt"

if [ -r $DUMMY ]; then
    echo "you have an instance open" >> $WARNING
else
    echo "rest of the shell script"
fi >& carga_$FECHA.log

When the cron job starts the shell executes and this generates the log WARNING but doesn't generate the log carga_$FECHA.log that's on the end of the if statement. I tried adding 2>> carga_$FECHA.log and it sends me an e-mail with the content of the log file and then this:

X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin>
X-Cron-Env: <HOME=/home/ecabanas>
X-Cron-Env: <LOGNAME=ecabanas>
X-Cron-Env: <USER=ecabanas>
Sirex
  • 5,499
  • 2
  • 33
  • 54
darm323
  • 9
  • 1

1 Answers1

1

Remember that cron starts with almost no environment variables set with the exception of a few. Looks like you are depending on variables set in your environment that are NOT in your cron environment.

You must change the cron scripting to set definitions to all variables you are using that are not the five listed. Sorry, that is the way it is.

Sirex
  • 5,499
  • 2
  • 33
  • 54
mdpc
  • 11,856
  • 28
  • 53
  • 67