1

I can run the command aws --version in a script and in the cli. But if I put this command into a crontab it does not work.

Crontab:

50 12 * * * aws --version > ~/yolo.swag

Error:

/bin/sh: 1: aws: not found

The aws command is in a bash script. And I get the same error message when I run the script in cron. How can I get the script to run the command fine ?

  • can you paste also content of your cron ? crontab -l ? Most probably you should put in your cron something like: SHELL=/bin/bash */1 * * * * aws --version – klerk Aug 3 '15 at 12:51
  • I have added my crontab. I think the path to the AWS command is as follows: /usr/local/bin/aws . How do I do that ? Remember that this is not bash, its a separate appliaction. – Infinite Aug 3 '15 at 12:56
9

You need to specify the full path to the aws executable:

50 12 * * * /usr/local/bin/aws --version > ~/yolo.swag
  • This worked fine. I have updated my question though. As the aws command I am actually running needs to work within my bash script. – Infinite Aug 3 '15 at 13:07
  • I have done so. How can I set the aws path globally ? – Infinite Aug 3 '15 at 13:13
  • These tips also might help you to understand cron behavior: krisjordan.com/essays/timesaving-crontab-tips – klerk Aug 3 '15 at 13:18
  • The path is already absolute (/usr/local/bin/aws) if you to be able to call it just with 'aws' put it in your root PATH variable. – Baazigar Aug 3 '15 at 15:38
1

Put this code before your command line to be executed into crontab -e

SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

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.