Solved

Ubuntu CRON doesn't run bash scripts

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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
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…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Suggested Courses

739 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