LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-07-2015, 08:27 AM   #1
BWestOz
LQ Newbie
 
Registered: Dec 2013
Location: Perth WA
Posts: 18

Rep: Reputation: Disabled
cron not running shell script


Ubuntu 14.10

cron not running shell script

I'm having difficulty getting a shell script to work using cron.

I'm doing everything as root user (sudo su).

The script is /var/www/crontest.sh

containing
--
#!/bin/bash

echo "cron test at $(date)" >> crontest.txt
--

The script works if I run it from the command line (ie can see entries in crontest.txt).

In desperation I've chmodded 777 crontest.sh and crontest.txt.

I've added it to spooled crontab file for root using

crontab -e

I've tried each of these

* * * * * /var/www/crontest.sh

1/* * * * * /var/www/crontest.sh

* * * * * /bin/bash /var/www/crontest.sh

1/* * * * * /bin/bash /var/www/crontest.sh

I've also tried editing the /etc/crontab file with each of these

* * * * * root /var/www/crontest.sh
1/* * * * * root /var/www/crontest.sh
* * * * * root /bin/bash /var/www/crontest.sh
1/* * * * * root /bin/bash /var/www/crontest.sh

I've checked that cron is running with

ps -e | grep cron

I've retsarted cron (/etc/init.d/cron restart) & rebooted.

So far nothing has worked.

Any suggestions appreciated.
 
Old 01-07-2015, 08:30 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,133

Rep: Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273
What do you mean by "so far nothing has worked"?
Try to use full path, so write:
echo "cron test at $(/bin/date)" >> /tmp/crontest.txt
 
1 members found this post helpful.
Old 01-07-2015, 08:32 AM   #3
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 2,957

Rep: Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845
1. use [code] and [/code] tags
2. to debug, add these lines into your scripts:
Code:
set -xv
exec >/tmp/debug.$$ 2>&1
 
Old 01-07-2015, 08:41 AM   #4
BWestOz
LQ Newbie
 
Registered: Dec 2013
Location: Perth WA
Posts: 18

Original Poster
Rep: Reputation: Disabled
Thank you.

I did a search with

find / | grep crontest.txt

and discovered a crontest.txt file in root's home directory with all the date entries in it.

I changed to the absolute path as you suggested.

Silly me!

Thanks for helping me solve it

Cheers
 
Old 01-07-2015, 08:45 AM   #5
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,133

Rep: Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273
glad to help you
If you really want to say thanks just press YES.
Also please mark the thread SOLVED (if you are satisfied)
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Issue in running shell script using cron job in Unix server. Mundlamuri Programming 7 07-12-2011 12:37 PM
[SOLVED] CRON : running shell script as root Sean1e Linux - Software 3 06-16-2011 12:04 PM
[SOLVED] Shell Script Not Working in Cron 3rods Linux - Newbie 6 02-10-2010 09:24 PM
Running shell scripts with cron Lossenelin Linux - General 2 09-24-2009 03:51 PM
shell script using /etc/cron.hourly to execute cron.php file? rioguia Programming 3 06-11-2008 09:09 AM


All times are GMT -5. The time now is 11:10 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration