Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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/

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 SHLIB_PATH=$ORACLE_HOME/lib:/usr/lib/Motif1.2
export ORA_NLS33=$ORACLE_HOME/ocommon/nls/admin/data
export TMPDIR=/tmp
export DESA_HOME=/home/manager
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

if [ -r $DUMMY ]; then
    echo "you have an instance open" >> $WARNING
    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>
share|improve this question

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.