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.

1 Answer 1

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.

1
  • I don't know how I missed that. Thanks :)
    – arjunurs
    Aug 28, 2012 at 6:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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