Solved

Ubuntu CRON doesn't run bash scripts

Posted on 2013-07-01
5
559 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 500 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

How many times have you wanted to quickly do the same thing to a list but found yourself typing it again and again? I first figured out a small time saver with the up arrow to recall the last command but that can only get you so far if you have a bi…
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

740 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