Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Possible Duplicate:
Reasons why crontab does not work

I'm migrating some scripts from an older machine to a lucid ec2 machine.
I'm sourcing a file in our ~/.bashrc and setting some environment variables, but those variables don't seem to be accessible from any cron.
Even though my cron has a . /home/username/.bashrc && /path/to/script the script doesn't seem to know of any of the environment variables which is in another file and sourced in ~/.bashrc.

All of these scripts work successfully when I run them from the command line. While trying to run it from a crontab, however, they fail.

share|improve this question
add comment

marked as duplicate by enzotib, jrg, Marco Ceppi Sep 20 '11 at 14:33

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer

up vote 2 down vote accepted

Each line in your cron will be executed by a separate process. Perhaps you should run them inside a subshell? * * * * * root (. /home/nigel/.bashrc && script).

Also, your .bashrc will usually have assumptions about it being a login shell (certain variables are assumed and their absence might make the script crash). For example, your .bashrc might start with this line, which means that nothing from your .bashrc will take effect when run from cron:

[ -z "$PS1" ] && return

You might want to try with a small script that just has variable settings.

share|improve this answer
    
Exactly what I did! Thanks guys :-) –  Nigel Sep 21 '11 at 6:49
    
Good example Wes. Thanks! –  Noufal Ibrahim Sep 21 '11 at 6:52
add comment

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