LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 10-01-2008, 11:54 AM   #1
hazmatt20
Member
 
Registered: Jan 2006
Distribution: FC5, Ubuntu
Posts: 126

Rep: Reputation: 15
Script not being run in cron.daily


I have a backup script that I run on a few machines, but I'm having a problem with one of them. The script is sitting under /etc/cron.daily, but it isn't run when cron.daily is run. When it is run, it should put the date in a log file, but it doesn't, although it did several weeks ago. I've run cron directly, so I know it's not a problem with cron. I can run the script directly.
 
Old 10-01-2008, 12:12 PM   #2
jailbait
LQ Guru
 
Registered: Feb 2003
Location: Virginia, USA
Distribution: Debian 12
Posts: 8,337

Rep: Reputation: 548Reputation: 548Reputation: 548Reputation: 548Reputation: 548Reputation: 548
cron has a different PATH than running from the command line. It is a common problem for a script to work from the command line and not work in cron. You can fix this problem by using the complete path for every command in your script.

Another solution is to set the PATH in the cron script to be exactly the same as the PATH used at the command line.

--------------------
Steve Stites
 
Old 10-01-2008, 11:42 PM   #3
hazmatt20
Member
 
Registered: Jan 2006
Distribution: FC5, Ubuntu
Posts: 126

Original Poster
Rep: Reputation: 15
The script only uses if, ls, rsync, and echo. It also works on two other computers.
 
Old 10-02-2008, 12:54 AM   #4
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
You should do as Jailbait suggests. One difference could be that on that computer, one of the commands is aliased and that is causing a problem. It is standard practice to always include full pathnames in cron scripts. There is also a security consideration as well.

Another thing to check is that you redirect both stdio and stderr.
 
Old 10-03-2008, 11:26 AM   #5
hazmatt20
Member
 
Registered: Jan 2006
Distribution: FC5, Ubuntu
Posts: 126

Original Poster
Rep: Reputation: 15
The only thing I can think of is that whatever user is calling the scripts in cron.daily doesn't have permission to do some things. I made a script, test.sh, that contains the following:

#!/bin/bash
echo 'test `date` >> /var/log/test'

the file exists, but nothing gets written to it. Any suggestions?

Also, by full pathnames do you mean using /bin/echo instead of just echo?
 
Old 10-03-2008, 12:07 PM   #6
jailbait
LQ Guru
 
Registered: Feb 2003
Location: Virginia, USA
Distribution: Debian 12
Posts: 8,337

Rep: Reputation: 548Reputation: 548Reputation: 548Reputation: 548Reputation: 548Reputation: 548
Quote:
Originally Posted by hazmatt20 View Post

by full pathnames do you mean using /bin/echo instead of just echo?
Yes, assuming that echo is in /bin. You can find out where echo is with:

which echo

--------------------------
Steve Stites
 
Old 10-04-2008, 06:24 PM   #7
hazmatt20
Member
 
Registered: Jan 2006
Distribution: FC5, Ubuntu
Posts: 126

Original Poster
Rep: Reputation: 15
I tried:
Code:
#!/bin/bash

/bin/echo "bin/echo" > /tmp/test
/usr/bin/id >> /tmp/test
and nothing happened. Syslog shows that cron.daily was run. What is the problem?
 
Old 10-07-2008, 12:08 AM   #8
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
Try
"/bin/echo "bin/echo" >/tmp/test 2&>1
/usr/bin/id >> /tmp/test 2&>1

Redirect the file first so that you first redirect stdio to the file before attaching stderr.
 
Old 10-07-2008, 01:46 AM   #9
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Also, if cron does have an issue, it should/usually email the crontab owner (in this case root) with the problem/results. Login as root on the cmd line and use mailx or mail to check.
 
Old 10-10-2008, 01:03 AM   #10
hazmatt20
Member
 
Registered: Jan 2006
Distribution: FC5, Ubuntu
Posts: 126

Original Poster
Rep: Reputation: 15
I ran
Code:
/bin/echo "bin/echo" > /tmp/test 2&>1
and it wrote bin/echo 2 into /tmp/1. Also, mail sent to root is sent to my actual email address, and I've never gotten problems with cron.
 
Old 10-12-2008, 08:24 PM   #11
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
This

2&>1

ios wrong, should be

2>&1

i/o chn 2 (stderr ) out to address of chan 1 (stdout)
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
adding a perl script to cron.daily / cron.d to setup a cron job CrontabNewBIE Linux - Software 6 01-14-2008 08:16 AM
Shell script in cron.daily ;Where does the log go ? jeepescu Linux - General 2 12-03-2007 06:07 PM
change cron.daily run time jimmyjiang Red Hat 4 03-02-2007 01:35 PM
How to run jobs in /etc/cron.daily? Micro420 Linux - Newbie 4 10-19-2006 02:07 PM
Problem With Script in cron.daily fizbang Linux - Newbie 10 03-21-2005 10:23 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:07 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