[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Ubuntu CRON doesn't run bash scripts

Posted on 2013-07-01
5
Medium Priority
?
581 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 48

Expert Comment

by:Tintin
ID: 39291747
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
ID: 39291753
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 2000 total points
ID: 39291788
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
ID: 39291982
What user is the cronjob running as?
0
 
LVL 2

Author Closing Comment

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

Featured Post

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

rdate is a Linux command and the network time protocol for immediate date and time setup from another machine. The clocks are synchronized by entering rdate with the -s switch (command without switch just checks the time but does not set anything). …
Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
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 navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Suggested Courses
Course of the Month14 days, 22 hours left to enroll

649 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