LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop
User Name
Password
Linux - Desktop This forum is for the discussion of all Linux Software used in a desktop context.

Notices


Reply
  Search this Thread
Old 07-20-2009, 03:02 PM   #1
soupnsandwich
Member
 
Registered: Jul 2009
Location: State of Rhode Island
Distribution: TBA
Posts: 34

Rep: Reputation: 15
Can't get any cron job to work!


Hi guys first time here. I'm a bit discouraged. After 3 solid days of trying to get a system wide cron job to run a simple script I'm out of options. I've read many forums postings and talked to quite a few people on different IRC channels and still no cron job will seem to work.

I'm working off of PCLinuxOS 2009.1.
The goal here is to run a script to run once a day everyday. This script goes to a server and checks to see if a text file exist and if it does it executes a simple notification popup...that's all.

I want this script to run for all users. I thought it was as simple as creating the script, setting the permissions and dropping it into /etc/cron.daily

I went to /etc/crontab and check to see what the time was set to and adjusted it so that it would execute a minute or two from the time I edited the file. I saved it..and nothing.

I also tried using the GUI tool Kcron to see if what it was doing was any different from what I was doing. The only difference is that it was adding a line to crontab file. The same way it would if you created a text file with the necessary information including time and the path to the script and then running "crontab nameoffile.txt" or if you were to do a "crontab -e" and edit or add a new cron entry with the VI editor.

I'm at a complete loss as to why this simple script isn't running.

I checked to see the system processes and "crond" is running so that's fine.
The script that I dropped into the /etc/cron.daily is executable...if I click on it, it runs perfectly.

Can anybody help with this issue?
Thanks guys....any assistance on this major pain would be much appreciated.

Soup
 
Old 07-20-2009, 03:08 PM   #2
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,528

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
Any pointers in the log files?
Make sure to use the whole path to the commands in the script.
 
Old 07-20-2009, 04:32 PM   #3
soupnsandwich
Member
 
Registered: Jul 2009
Location: State of Rhode Island
Distribution: TBA
Posts: 34

Original Poster
Rep: Reputation: 15
Thanks Repo.
well I'm not really sure what I should be looking at for the log.
I checked /var/spool/cron. There's a file called info...all that was there was some entries about anacron.
Is there a list of things I should try in order? Maybe with some guidance you guys can walk me through it to see if I'm messing something up.

Thanks
Soup
 
Old 07-20-2009, 05:59 PM   #4
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 677Reputation: 677Reputation: 677Reputation: 677Reputation: 677Reputation: 677
Logs are normally in /var/log/.

The cron environment is different. You don't have the same environmental variables set. So without a PATH variable, you need to use the full pathname for commands, as repo indicated.

Also, the script runs in the background without an attached terminal. So the program can't expect any input from stdin. It it writes to stdout or stderr, that output needs to be redirected to /dev/null or to a file.
 
Old 07-20-2009, 07:06 PM   #5
soupnsandwich
Member
 
Registered: Jul 2009
Location: State of Rhode Island
Distribution: TBA
Posts: 34

Original Poster
Rep: Reputation: 15
thanks very much Jschiwal

Ok I'll check /var/logs/cron tomorrow on the machine that I was testing on and see if there is any feedback when the cron job ran.
Please forgive my ignorance but could explain how to get the standard output from cron?
I will also make certain that the full path is added to the script.
So what is the correct way to use cron for a system job? I ask because it seems so simple if I look in /etc/cron.daily or any other cron. folder...the scripts are there, some of them are links...the permissions equal my scripts permissions I think it should work...no?

What is the absoulute minimum line in /etc/crontab for it to "look" at the script that I have in etc/daily
This is what's there now:

"SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# run-parts
01 * * * * root nice -n 19 run-parts --report /etc/cron.hourly
02 4 * * * root nice -n 19 run-parts --report /etc/cron.daily
22 4 * * 0 root nice -n 19 run-parts --report /etc/cron.weekly
42 4 1 * * root nice -n 19 run-parts --report /etc/cron.monthly"
Now since I'm running this as a whole system job shouldn't all I should have to do is set the time in the /etc/cron.daily line for..say 1:30 pm as

30 13 * * * root nice -n 19 run parts --report /etc/cron.daily?

Thanks guys
Soup
 
Old 07-20-2009, 11:38 PM   #6
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 677Reputation: 677Reputation: 677Reputation: 677Reputation: 677Reputation: 677
Dropping a script in cron-daily was the right thing to do. Your distro set up cron, so the actual cron job is set up to run any scripts found in the folders.

It is usually the case where each script does it's own logging. If there is a log from cron, it will probably just say whether cron daily was run or not. Also check the email for root. Some cron scripts, such as for logrotate may use the /bin/logger command to log errors to the system log.

For redirecting both stdout & stderr to a file, add "> logfile 2>&" to the end of the command.

Here is a snippit from a beagle cron job. It uses the variable DEBUG to allow you to debug the script before dropping it in.
Code:
           if [ "$DEBUG" = "1" ]; then
                eval $COMMAND
            else
                eval $COMMAND > /dev/null 2>&1
            fi
Something else that is often done is to group commands inside braces. That way you can redirect the output for all of the commands at once;

{
commandline1
commandline2
commandline3
} > /dev/null 2>&

You could have the output redirected to a log file instead.
For that use ">> /path/to/logfile 2>&"

Good Luck!

Last edited by jschiwal; 07-21-2009 at 12:03 AM.
 
Old 07-20-2009, 11:47 PM   #7
micxz
Senior Member
 
Registered: Sep 2002
Location: CA
Distribution: openSuSE, Cent OS, Slackware
Posts: 1,131

Rep: Reputation: 75
http://www.unixgeeks.org/security/ne...ix/cron-1.html
 
Old 07-24-2009, 09:18 AM   #8
soupnsandwich
Member
 
Registered: Jul 2009
Location: State of Rhode Island
Distribution: TBA
Posts: 34

Original Poster
Rep: Reputation: 15
Ok still working on this problem. It seems simple enough to get it working but it simply won't work. I'm going to run through it again following all the advise that you guys gave me and report back later.

THanks guys
Soup
 
Old 07-24-2009, 09:49 AM   #9
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,577
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Are any cron jobs running? Try looking in /var/log files daemon.log and syslog for evidence. Do either of the files /etc/cron.allow and /etc/cron.deny exist? If so, what's in them?
 
Old 07-24-2009, 12:16 PM   #10
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Debian "Testing"
Posts: 6,096

Rep: Reputation: 409Reputation: 409Reputation: 409Reputation: 409Reputation: 409
Don't forget the following:
- Scripts dropped into /etc/cron.daily need to be set as executable
- cron's environment is limited, so use /full/path/to/command in those scripts.

Does your script run correctly if you call it directly from the terminal?

And...
Quote:
This script goes to a server and checks to see if a text file exist and if it does it executes a simple notification popup...that's all.
Oh! It "executes a simple notification popup". To which :display does this script send its output? Does it have the necessary permissions to do this?
 
Old 07-24-2009, 04:30 PM   #11
soupnsandwich
Member
 
Registered: Jul 2009
Location: State of Rhode Island
Distribution: TBA
Posts: 34

Original Poster
Rep: Reputation: 15
Yes the scripts are executable and they do work when triggered from a terminal and directly from the /etc/cron.daily folder.
I've tried it with a sym link to the scipt and added the script itself to that folder and nothing so far. "crond" is running as a process on boot up so it's running.

Guys this is incredible. I'm going to set up a testing machine at home tomorrow and test the crap out of this. If you guys can think of anything else please let me know.
I'll be able to check the logs as soon as I get a fresh testing enviro. setup.

Thanks guy,
soup
 
Old 07-24-2009, 04:52 PM   #12
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Debian "Testing"
Posts: 6,096

Rep: Reputation: 409Reputation: 409Reputation: 409Reputation: 409Reputation: 409
Quote:
To which :display does this script send its output? Does it have the necessary permissions to do this?
You didn't answer this Q.
 
Old 07-24-2009, 05:07 PM   #13
micxz
Senior Member
 
Registered: Sep 2002
Location: CA
Distribution: openSuSE, Cent OS, Slackware
Posts: 1,131

Rep: Reputation: 75
Do you mind posting the content the script itself?
 
Old 07-24-2009, 11:27 PM   #14
soupnsandwich
Member
 
Registered: Jul 2009
Location: State of Rhode Island
Distribution: TBA
Posts: 34

Original Poster
Rep: Reputation: 15
Hmmm I'm not sure about that. Well the script contains a Zenity command and a command that reads something like "notify-send -t 0 "Message Title Here" "Body of the popup message here"
But if the script runs as a single command in a terminal...and it runs when clicking on the executable script file and I don't have to tell it what display to use...why should I have to tell cron that info? Is cron really that different that it needs that info also??
Micxz the above is really all the script reads...but if you need a quote I can get that for you tomorrow

How do I tell cron what display to use? Do I actually modify the existing script to do that?

soup

Thanks guys!
 
Old 07-24-2009, 11:59 PM   #15
micxz
Senior Member
 
Registered: Sep 2002
Location: CA
Distribution: openSuSE, Cent OS, Slackware
Posts: 1,131

Rep: Reputation: 75
Yes it is display cause cron run in a different environment then your shell or desktop. So just add the env vars you need as in:

Code:
*/1 * * * * DISPLAY=:0.0 /usr/bin/notify-send Test "This is a test"
 
  


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
cron job doesnt work, it works manually scofiled83 Programming 8 05-30-2009 03:12 PM
Why my cron job doesn't work byng08 Linux - Newbie 7 11-26-2008 01:17 AM
adding a perl script to cron.daily / cron.d to setup a cron job CrontabNewBIE Linux - Software 6 01-14-2008 08:16 AM
How do I get a cron job to work? socceroos Linux - Software 2 03-23-2006 04:22 PM
Cron Job petenyce Linux - Newbie 5 10-11-2005 04:03 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop

All times are GMT -5. The time now is 07:43 PM.

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