LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 04-04-2011, 11:33 AM   #1
mcdorians
LQ Newbie
 
Registered: Apr 2011
Posts: 6

Rep: Reputation: 0
Cron doesn't run a certain script


Hi,
i've tried to get cron to run a script, but it does not work.
At first I put it into /etc/cron.hourly, with no succsess. Then i added the line
Code:
*/1 * * * * root /etc/cron.hourly/change.sh
to the crontab, with the same result.
I'm sure cron runs fine besides that Problem, because commands like
Code:
*/1 * * * * root echo "test" > /tmp/test.txt
get executed.

Thanks in advance
dorian
 
Old 04-04-2011, 11:36 AM   #2
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,529

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
Welcome to LQ

Since cron uses a limited PATH,
make sure you use the whole path to all the commands and files in your script.
If there are errors with cron, it will sent a mail to root.
Look in the logfiles.
Does the script work if you run it from terminal?

Kind regards
 
1 members found this post helpful.
Old 04-04-2011, 11:46 AM   #3
mcdorians
LQ Newbie
 
Registered: Apr 2011
Posts: 6

Original Poster
Rep: Reputation: 0
The sript runs from the terminal.
Code:
#!/bin/bash

php /var/www/service_php/change/change.php
Is this Ok, ore should it be /usr/bin/php ?

Where can find the logfiles?


//Edit
i've changed it to /usr/bin/php /var/www/service_php/change/change.php, but it's still noch running

Last edited by mcdorians; 04-04-2011 at 12:34 PM. Reason: update
 
Old 04-04-2011, 12:47 PM   #4
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,529

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
Errors are mailed to root.
Look in /var/log/*for errors

Kind regards
 
Old 04-04-2011, 01:13 PM   #5
thund3rstruck
Member
 
Registered: Nov 2005
Location: East Coast, USA
Distribution: Fedora 18, Slackware64 13.37, Windows 7/8
Posts: 380

Rep: Reputation: 41
I was also having a problem running a script from my crontab ($ crontab -e). I discovered the error by grepping syslog

Code:
$ cat /var/log/syslog | grep -i cron
After some troubleshooting my problem turned out to be that I did not hit the 'enter' key after setting a cron task as it turned out that each cron line must end with a newline. Review the cron entries in the syslog and work backwards from there.

Last edited by thund3rstruck; 04-04-2011 at 01:14 PM. Reason: typo
 
1 members found this post helpful.
Old 04-04-2011, 01:16 PM   #6
mcdorians
LQ Newbie
 
Registered: Apr 2011
Posts: 6

Original Poster
Rep: Reputation: 0
Im not exactly sure if i'm looking at right place
Code:
Isengard:/var/mail# mail
No mail for root
And i've found some repots about cron just in /var/log/syslog, the is no seperate log like for mysql.
Code:
Apr  4 19:12:01 Isengard /USR/SBIN/CRON[6425]: (root) CMD (root /usr/bin/php /var/www/service_php/change/change.php)
Apr  4 19:12:01 Isengard /USR/SBIN/CRON[6426]: (root) CMD (root /etc/cron.hourly/change.sh)
Apr  4 19:12:01 Isengard /USR/SBIN/CRON[6427]: (root) CMD (root echo "test" > /tmp/test.txt)
 
Old 04-04-2011, 01:27 PM   #7
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,529

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
Quote:
Apr 4 19:12:01 Isengard /USR/SBIN/CRON[6425]: (root) CMD (root /usr/bin/php /var/www/service_php/change/change.php)
Apr 4 19:12:01 Isengard /USR/SBIN/CRON[6426]: (root) CMD (root /etc/cron.hourly/change.sh)
Apr 4 19:12:01 Isengard /USR/SBIN/CRON[6427]: (root) CMD (root echo "test" > /tmp/test.txt)
This means the cron job has been executed.
So the problem is your script
You could use
Code:
*/1 * * * * root /etc/cron.hourly/change.sh> /tmp/log.txt 2>&1
To see the output.
You should also verify the permissions.

Kind regards
 
Old 04-04-2011, 01:41 PM   #8
mcdorians
LQ Newbie
 
Registered: Apr 2011
Posts: 6

Original Poster
Rep: Reputation: 0
As I said the script runs in the Terminal.

But i get this as a Result in the /tmp/log.txt
Code:
/bin/sh: root: command not found
which is different from the output i get by running it from the Terminal.
i've done chmod 0777 on the file.
 
Old 04-04-2011, 01:53 PM   #9
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,529

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
Quote:
/bin/sh: root: command not found
Did you create the cronjob as root or as user?
You need to create it as root.
Only root can add a user, a users cron job expects a command after the last "*"
You could drop the script
Code:
change.sh
in the /etc/cron.hourly
directory, to make it run every hour.
Or remove root from the cron, since it will run as root.

Kind regards

Last edited by repo; 04-04-2011 at 01:58 PM.
 
Old 04-04-2011, 02:30 PM   #10
mcdorians
LQ Newbie
 
Registered: Apr 2011
Posts: 6

Original Poster
Rep: Reputation: 0
i removed the root und put a copy of change.sh into hourly. But it seams that the script didn't run.
Now i get a permission denied error in the log.txt
What schould i do to make the script executable for cron
Code:
Isengard:/etc/cron.hourly# ls -l
total 4
-rwxrwxrwx 1 root root 63 2011-04-04 17:46 change.sh
 
Old 04-04-2011, 02:40 PM   #11
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,529

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
Quote:
i removed the root und put a copy of change.sh into hourly. But it seams that the script didn't run.
Where did you removed root?
You can't use both.
Or you empty the roots cronjob using
Code:
crontab -e
as root and put change.sh in the /etc/cron.hourly directory
When you put it in the /etc/cron.hourly directory, you don't need to create a cronjob,
the files in the directory will be executed every hour.
Or you use
Code:
crontab -e
as root
to setup the crontab, and remove change.sh from the /etc/cron.hourly
directory, and put it in another directory, and point the cronjob to the new directory.
Code:
*/1 * * * *  /PATH_TO/change.sh
Please post the content from
change.sh

Kind regards

Last edited by repo; 04-04-2011 at 02:44 PM.
 
Old 04-04-2011, 03:28 PM   #12
mcdorians
LQ Newbie
 
Registered: Apr 2011
Posts: 6

Original Poster
Rep: Reputation: 0
Code:
Isengard:/var/www/service_php/change# cat /root/change.sh
#!/bin/bash
/usr/bin/php /var/www/service_php/change/change.php
It woks now, i guess it failed due to the entry in the crontrab an the simultaneous location in the cron.hourly.

Thaks you all for your Help especialy repo. Haven't fix this without your advices.
 
Old 04-04-2011, 03:35 PM   #13
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,529

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
No problem.
You can mark the thread solved using the thread tools.

Kind regards
 
  


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
Run script from cron - problem froxxiieee Linux - Software 2 07-01-2010 10:13 AM
Samba PDC without roaming profiles - Vista login doesn´t run script! owen.roberts Linux - Server 3 06-23-2009 09:01 PM
cannot get tu run a php script in cron alain Linux - General 6 02-06-2006 03:54 AM
FTP Script will not run from Cron grhansen Programming 12 01-13-2006 05:13 AM
can't get cron to run my script. dr_zayus69 Linux - Software 6 04-12-2005 07:34 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:12 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
Open Source Consulting | Domain Registration