I'm using a script which is working in Stand alone and is not working through the cron job .

qexma1@test:bin> head -n 10 test.sh
declare -r PATH='/sbin:/bin:/usr/sbin:/usr/bin'
source $AEM_CONFIG/aem-wrap.conf

Cron Job :

qexma1@test:bin> crontab -l | grep aem-test.sh
01 15 * * * bin/test.sh -b ; touch bin/crontest.txt;

Flag :

qexma1@test:bin> ll bin/ | grep cron
-rw-r--r--  1 qexma1 abc   0 Nov 11 15:01 crontest.txt

Flag file got created crontest.txt but script didn't get executed. Permissions 0755

  • Suggest you replace /global/appaem/aem/bin/aem-test.sh -b with /global/appaem/aem/bin/aem-test.sh -b >/tmp/mylog 2>&1 and then update question with the output recorded in /tmp/mylog. Where/how are you expecting $AEM_CONFIG to be getting initialised ? – steve Nov 11 '16 at 14:10
  • 1
    $AEM_CONFIG is a Environment variable and part of a script – robotTech Nov 11 '16 at 14:12

As the output to stderr is as below, it means variable $AEM_CONFIG is not getting set. That is why the job fails.

/global/appaem/aem/bin/aem-test.sh: line 5: /aem-wrap.conf: No such file or directory

To fix the issue, revise the script to source the relevant file that sets $AEM_CONFIG.

As you point out the variable is defined in .bashrc, see cron ignores variables defined in “.bashrc” and “.bash_profile”. You need to add a line such as source ~/.bashrc into your script. Example:

declare -r PATH='/sbin:/bin:/usr/sbin:/usr/bin'
source ~/.bashrc
source $AEM_CONFIG/aem-wrap.conf
| improve this answer | |
  • any idea why environment variable is not being picked $AEM_CONFIG?? – robotTech Nov 11 '16 at 14:40
  • Where/how are you expecting $AEM_CONFIG to be getting initialised ? It is not initialised and set to any value in the script info seen so far. – steve Nov 11 '16 at 14:54
  • It's environment var. configured under .bashrc echo $AEM_CONFIG /global/appaem/aem/etc/aem-config – robotTech Nov 11 '16 at 15:02
  • .bashrc is not run via cron. Answer revised to make this clear and offer solution. – steve Nov 11 '16 at 17:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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