0

I am trying to output the most recent changelist number from our source control software to a log file. I know that the script works fine until getting the changelist number. The script below works when I run it manually but doesn't seem to work when it is triggered from the crontab. I have no idea why it wouldn't work. I am running this script on a machine with Mac OS X 10.7 and the permission are set to 555.

changelist=${changelist_ouput}

output_file="../../output_dir/result_log.txt"

if [[ -e ${output_file} ]];
then
    # Delete previous changelist information
    sed -i.bak '/changelist/d' "${output_file}"
    rm "${output_file}.bak"

    # Add current changelist information
    echo "changelist=${changelist}" >> "${output_file}"
else
    echo "WARNING: Failed to update changelist information"
fi

I would appreciate any help.

arjunurs
  • 1,062
  • 2
  • 17
  • 29

1 Answers1

2

cron probably isn't using the same current directory as you are using. Since you use a relative path for output_file, this will dump the output to some path relative to cron's current directory (and since ../../output_dir probably doesn't exist, it'll just fail).

You have to use an absolute path for output_dir, or make a path relative to the script directory (dirname $0). See also Crontab - Run in directory.

Community
  • 1
  • 1
nneonneo
  • 171,345
  • 36
  • 312
  • 383