Solved

Ubuntu CRON doesn't run bash scripts

Posted on 2013-07-01
5
548 Views
Last Modified: 2013-07-02
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?
0
Comment
Question by:David11011
  • 2
  • 2
5 Comments
 
LVL 48

Expert Comment

by:Tintin
Comment Utility
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
0
 
LVL 2

Author Comment

by:David11011
Comment Utility
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.
0
 
LVL 40

Accepted Solution

by:
omarfarid earned 500 total points
Comment Utility
make sure that

- you set env variables required for the script to run
- you use full path names to files / folders/ commands you use in the script
- the script is executable (use chmod +x scriptname)
0
 
LVL 48

Expert Comment

by:Tintin
Comment Utility
What user is the cronjob running as?
0
 
LVL 2

Author Closing Comment

by:David11011
Comment Utility
That was it. I changed the file permissions and now it runs like a champ. Thanks.
0

Featured Post

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now