Link to home
Start Free TrialLog in
Avatar of David11011
David11011Flag for United States of America

asked on

Ubuntu CRON doesn't run bash scripts

I've got a bash script
#!/bin/bash
sudo touch /test/scriptTest.txt

Open in new window


that is saved to /backup_ABOL.sh

I've opened my crontab file with "sudo crontab -e" and added these lines
03 16 * * * /backup_ABOL.sh
03 16 * * * sudo touch /test/cronTest.txt

Open in new window


When the CRON job runs, the cronTest.txt file is created but the file from the bash script isn't created.

When I run the script manually ". /backup_ABOL.sh" it creates the file without any problems.

These are the things I've tried in the CRONTAB file

03 16 * * * /backup_ABOL.sh

03 16 * * * ./backup_ABOL.sh

03 16 * * * . /backup_ABOL.sh

03 16 * * * /bin/bash /backup_ABOL.sh

03 16 * * * /bin/bash . /backup_ABOL.sh

SHELL=/bin/bash
03 16 * * * /backup_ABOL.sh

SHELL=/bin/bash
03 16 * * * . /backup_ABOL.sh

SHELL=/bin/bash
03 16 * * * ./backup_ABOL.sh

Open in new window

none of them will run the script. any ideas?
Avatar of Tintin
Tintin

What user are you creating the cronjob as?

Does backup_ABOL.sh really exist in /

You would need root perms to place it in the root dir.

I suspect it is really in your home dir, in which case do

13 16 * * * /home/username/backup_ABOL.sh
Avatar of David11011

ASKER

It really is at /.

I've tried copying the file to my home directory and putting the path into the CRONTAB file but it doesn't make any difference. It still doesn't run. I would rather have it at the directory root because it will be much easier to find later. I log into this server like 2x a year.
ASKER CERTIFIED SOLUTION
Avatar of omarfarid
omarfarid
Flag of United Arab Emirates image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
What user is the cronjob running as?
That was it. I changed the file permissions and now it runs like a champ. Thanks.