Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Continuing from a Stackoverflow question, I've got a .sh that tries to (1) run a script that sets environment vars and then (2) runs a php script.

The crontab entry (have tried with and without >> output):

 */1 * * * * /home/user/public_html/domain.com/private/ec2-api-tools/php/doQueue.sh >> /home/user/output.txt

The script, doQueue.sh (running this by hand works):

#/bin/sh
. ./environment.sh
php process_queue.php

The environment.sh (again, works by hand):

#!/bin/sh
echo "running environment"
PATH=$EC2_HOME/bin:$PATH
EC2_HOME=/home/user/public_html/domain.com/private/ec2-api-tools
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/user/public_html/domain.com/private/ec2-api-tools/bin
MAIL=/var/mail/root
PWD=/home/user/public_html/domain.com/private/ec2-api-tools
JAVA_HOME=/usr/lib/jvm/java-6-sun/jre/
LANG=en_US.UTF-8
EC2_PRIVATE_KEY=/home/user/public_html/domain.com/private/ec2-api-tools/pk-hash.pem
EC2_CERT=/home/user/public_html/domain.com/private/ec2-api-tools/cert-hash.pem

I've tried variations using sh and . to no avail. What's the best way to troubleshoot this?

share|improve this question
    
Is this in /var/spool/cron/crontabs or /etc/cron.d/ (the latter requires the user to run the job as)? Have you tried putting debug statements in doQueue.sh to get some output to verify that it's running? –  Andrew Jul 21 '10 at 3:21
    
So what I was missing was that I needed to "export" the vars into the environment. Please change this comment to a response and I'll pick your answer and close the question. –  editor Jul 21 '10 at 3:30

3 Answers 3

up vote 0 down vote accepted

Is this in /var/spool/cron/crontabs/ or /etc/cron.d/ (the latter requires the user to run the job as)?

Have you tried putting debug statements in doQueue.sh to get some output to verify that it's running?

share|improve this answer

Make sure crontab file ends with a newline

share|improve this answer
#/bin/sh
. ./environment.sh

!

And what is the CWD when the script runs? Try specifying the absolute path to environment.sh

That would explain why the cron job doesn't actually work, but not why it never fires at all.

By default, cron mails the local user with the output of jobs and error messages - have you checked this?

Are you sure that the job exists in the cron file? (i.e. what do you see when you type in 'crontab -l' at the prompt).

HTH

C.

share|improve this answer
    
....and check that crond is running and the user is allowed to run cron jobs of course –  symcbean Jul 21 '10 at 10:16

Your Answer

 
discard

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.