LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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-25-2009, 12:43 AM   #16
micxz
Senior Member
 
Registered: Sep 2002
Location: CA
Distribution: openSuSE, Cent OS, Slackware
Posts: 1,131

Rep: Reputation: 75

And remember to hit the thumbs up button on tredegar's post.
 
Old 07-25-2009, 02:33 AM   #17
alpha01
Member
 
Registered: Jul 2008
Location: Orange County
Distribution: Ubuntu/Debian, CentOS, RHEL, FreeBSD, OS X
Posts: 75

Rep: Reputation: 19
If you have a working mail server. I set always set the mailto variable to MAILTO='My_email_address' when trying to troubleshoot cron related issues.
 
Old 07-26-2009, 09:52 AM   #18
soupnsandwich
Member
 
Registered: Jul 2009
Location: State of Rhode Island
Distribution: TBA
Posts: 34

Original Poster
Rep: Reputation: 15
Hi guys,
finally got some time to mess with this cron issue.
Ok I set up a test machine just for this issue.

I also don't think it's a "display" setting because I put a simple copy of the "firefox" script into the cron.hourly and that didn't work and the permissions where fine.

here is the crontab file after the mod with the display. Permissions shouldn't be a problem because the file resided in the /usr/bin dir but I moved the actual script to the /etc/cron.hourly dir and then set the mins setting to 3 mins ahead of the time I tested it. I restarted the crond service ("service -f crond" and it restarted. The time came and went without anything.

************************************************************************************

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

# run-parts
26 * * * * root nice -n 19 run-parts --report DISPLAY=:0.0 /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
*******************************************************************************
Catkin no the crontab.deny or/and crontab.allow files do not exists. I have tried added the "crontab.deny" and keeping the file blank. I did this because this cron job must run for all users on the system.


******************************************************************************
Log from /var/log/damons:

Jul 26 10:20:46 Devel nmbd[3581]: [2009/07/26 10:20:46, 0] nmbd/nmbd_become_lmb.c:become_local_master_stage2(396)
Jul 26 10:20:46 Devel nmbd[3581]: *****
Jul 26 10:20:46 Devel nmbd[3581]:
Jul 26 10:20:46 Devel nmbd[3581]: Samba name server DEVEL is now a local master browser for workgroup DESERTNET on subnet 192.168.15.102
Jul 26 10:20:46 Devel nmbd[3581]:
Jul 26 10:20:46 Devel nmbd[3581]: *****
*******************************************************************************
This is the log from /var/log/syslog

Jul 26 10:22:15 Devel logger: - /var/spool/samba
Jul 26 10:22:19 Devel anacron[2023]: Job `cron.daily' terminated
Jul 26 10:24:21 Devel crond[14601]: (CRON) STARTUP (V5.0)
Jul 26 10:25:01 Devel crond[14601]: (*system*) RELOAD (/etc/crontab)
Jul 26 10:25:03 Devel anacron[2023]: Job `cron.weekly' started
Jul 26 10:25:03 Devel anacron[14660]: Updated timestamp for job `cron.weekly' to 2009-07-26
Jul 26 10:25:29 Devel anacron[2023]: Job `cron.weekly' terminated
Jul 26 10:25:29 Devel anacron[2023]: Normal exit (2 jobs run)
Jul 26 10:26:01 Devel crond[14601]: (*system*) RELOAD (/etc/crontab)
Jul 26 10:26:01 Devel crond[18567]: (root) CMD (nice -n 19 run-parts --report DISPLAY=:0.0 /etc/cron.hourly)
Jul 26 10:27:01 Devel crond[14601]: (*system*) RELOAD (/etc/crontab)
Jul 26 10:31:45 Devel crond[19009]: (CRON) STARTUP (V5.0)
Jul 26 10:33:01 Devel crond[19110]: (root) CMD (nice -n 19 run-parts --report DISPLAY=:0.0 /usr/bin/Notify)
Jul 26 10:37:01 Devel crond[19009]: (*system*) RELOAD (/etc/crontab)
Jul 26 10:37:46 Devel crond[19529]: (CRON) STARTUP (V5.0)
**********************************************************************************
Guys how do I check the mail for root? Where does that go?

Soup
 
Old 07-26-2009, 10:33 AM   #19
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by soupnsandwich View Post
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!
Yes cron is that different; it's running as a daemon without a controlling terminal and jobs run in a process environment that has not passed through login initialisation.

Three suggestions:
  1. Simulate the login environment in your script by changing the first line of your script to
    Code:
    #!/bin/bash -l
    That's a letter l and makes the non-login shell do login initialisation.
  2. Comment out the zenity command. If the script runs then you know that's the problem and you can focus on making it work or finding another way of achieving what you want.
  3. Add some debug lines to the script, writing to a file, so you can see if it started and how far it got.
    Code:
    echo 'DEBUG 10 (just started)' 2>/tmp/DEBUG.$$ >&2
    <commands>
    echo 'DEBUG 20 (finished stuff)' 2>/tmp/DEBUG.$$ >>&2
    That's not very smart or great practice but OK for quick and dirty debugging.

Regards root mail, any new mail sits in /var/spool/mail/root by default but this can have been changed in several ways. Maybe find it with
Code:
/var/opt/MyBackup.sh# find / -wholename /etc -prune -o -wholename /usr -prune -o -wholename /home -prune -o -wholename /proc -prune -o -type f -iname '*mail*' -o -iname '*root*'
That's best run as root to avoid error messages and could produce quite a bit of output; you might want to tee it into a temporary file or page it. That's not very smart either but OK for quick and dirty investigation.

Best

Charles
 
Old 07-26-2009, 02:13 PM   #20
micxz
Senior Member
 
Registered: Sep 2002
Location: CA
Distribution: openSuSE, Cent OS, Slackware
Posts: 1,131

Rep: Reputation: 75
Quote:
Originally Posted by soupnsandwich View Post
26 * * * * root nice -n 19 run-parts --report DISPLAY=:0.0 /etc/cron.hourly
I would take the "DISPLAY=:0.0" part out. Add to the top of your script (not crontab):
Code:
export DISPLAY=:0.0
then drop it in hourly. This should fix it.

For the mail part as root type "mail" you should get the mail for root. And if you would like root mail forwarded elsewhere you can add a file called ".forward" (mind the .dot.) in root's home directory containing "youremail@emailaddress.com"
 
Old 07-26-2009, 09:28 PM   #21
soupnsandwich
Member
 
Registered: Jul 2009
Location: State of Rhode Island
Distribution: TBA
Posts: 34

Original Poster
Rep: Reputation: 15
Ok
thanks guys for your efforts so far.
I tried everything that you guys have suggested so far with nothing actually working...I can't believe this!

Ok...how about this. What is the absolute minimum script and crontab that will work?

I replaced my script with a script that simply read "#!/bin/sh (or #!/bin/bash)
"/usr/bin/firefox"
"exit 0"
Even this didn't work!
What is the minimum for the crontab file itself?
soup (chris)
 
Old 07-26-2009, 10:00 PM   #22
soupnsandwich
Member
 
Registered: Jul 2009
Location: State of Rhode Island
Distribution: TBA
Posts: 34

Original Poster
Rep: Reputation: 15
Ok guys..here what did work! Although I'm not sure why.

Ok this is the script that worked...but it worked not by depending on the default crontab in /etc/

Instead I did this in a terminal
Quote:
crontab -e
i
55 22 * * /etc/cron.hourly/Notify-critical > /dev/null
ESC
:wq
Now why did this work and why does this entry not show up in the /etc/crontab file?

If I add the line above "55 22 * * /etc/cron.hourly/Notify-critical > /dev/null" to the existing crontab file in etc..it doesn't work.

Where is this new entry using the crontab -e command being created and why doesn't it work with the same entry in the existing /etc/crontab file when it points to the /etc/cron.hourly directory?
***********************************************************************
Quote:
#!/bin/sh

export DISPLAY=:0.0


file="wget --spider http://www.websitehere.com/Notify/Notify-critical.txt"

if $file; then
echo "file exists"
notify-send --urgency=critical -i /usr/share/icons/notify48.png -t 0 "CRITICAL Notification Alert"

zenity title=$"Notification Alert" --notification\
--window-icon="/usr/share/icons/notify48.png" \
--text="There is one or more CRITICAL system notification(s)
available for your system. Please click here to visit
the notification page for more information
**This message will be disabled in 1 week**"
www-browser www.websitehere.com

else
echo "file doesn't exist"
exit 0
fi

Last edited by soupnsandwich; 07-26-2009 at 10:15 PM.
 
Old 07-26-2009, 10:11 PM   #23
micxz
Senior Member
 
Registered: Sep 2002
Location: CA
Distribution: openSuSE, Cent OS, Slackware
Posts: 1,131

Rep: Reputation: 75
Quote:
Originally Posted by soupnsandwich View Post
Now why did this work and why does this entry not show up in the /etc/crontab file?
This is the system wide crontab file. Individual users can have they're own crontab's as well. They are stored in /var/spool/cron/crontabs/<user> (Unix/Slackware/*BSD),
/var/spool/cron/<user> (RedHat) or /var/spool/cron/tabs/<user> (openSuSE), but might be kept elsewhere depending on what in*x flavor you're running.

Last edited by micxz; 07-26-2009 at 10:13 PM.
 
Old 07-26-2009, 10:58 PM   #24
soupnsandwich
Member
 
Registered: Jul 2009
Location: State of Rhode Island
Distribution: TBA
Posts: 34

Original Poster
Rep: Reputation: 15
micxz: So by using the "crontab -e" command as root it's just for root?
Did you mean that the /etc/crontab was system wide...correct?

Ok well how would I make it for the system using what I just did? Let me guess...it's not possible?

If that script worked that I had in /etc/cron.hourly/Notify-critical when using the command 'crontab -e" and then using VI to add an entry that read "30 23 * * * /etc/cron.hourly/Notify-critical > /dev/null"...shouldn't this exact line work in the /etc/crontab existing file?

After setting up that crontab using that command as root I logged out and back in as a normal user and it didn't work.

Totally confused
Soup

Last edited by soupnsandwich; 07-26-2009 at 11:00 PM.
 
Old 07-26-2009, 11:17 PM   #25
micxz
Senior Member
 
Registered: Sep 2002
Location: CA
Distribution: openSuSE, Cent OS, Slackware
Posts: 1,131

Rep: Reputation: 75
Quote:
Originally Posted by soupnsandwich View Post
micxz: So by using the "crontab -e" command as root it's just for root?
Did you mean that the /etc/crontab was system wide...correct?
Yes and Yes.
Quote:
Ok well how would I make it for the system using what I just did? Let me guess...it's not possible?
I'm sure I'm understand "what I just did...", but if your cron job is running as root whether it's from root's crontab or /etc/crontab it is running on the same system so it's system wide so to speak.
Quote:
If that script worked that I had in /etc/cron.hourly/Notify-critical when using the command 'crontab -e" and then using VI to add an entry that read "30 23 * * * /etc/cron.hourly/Notify-critical > /dev/null"...shouldn't this exact line work in the /etc/crontab existing file?
Yes. Some cron versions reload the files every minute, and some require restarting, but Vixie Cron just loads the files if they have changed.
Quote:
After setting up that crontab using that command as root I logged out and back in as a normal user and it didn't work.
You have the above command to run at 11:30 PM daily was it this time when you where logged in as the normal user?
 
Old 07-27-2009, 12:14 AM   #26
soupnsandwich
Member
 
Registered: Jul 2009
Location: State of Rhode Island
Distribution: TBA
Posts: 34

Original Poster
Rep: Reputation: 15
Oh man! Ok I ran the "crontab -e" as root and entered a new time to test it. It ran on time as root. I then ran the command again and moved the time forward about 5 mins. Logged off and back on as a normal users and it didn't run. So clearly a cron job for Root won't run for a normal user. I even created a "cron.deny" in /etc and left it blank as to give all users permission and I check again the permissions of the script that I'm point to which is in /ect/cron.hourly and it's wide open for all users.

What the heck is going on here?

soup
 
Old 07-27-2009, 12:38 AM   #27
micxz
Senior Member
 
Registered: Sep 2002
Location: CA
Distribution: openSuSE, Cent OS, Slackware
Posts: 1,131

Rep: Reputation: 75
Quote:
Originally Posted by soupnsandwich View Post
So clearly a cron job for Root won't run for a normal user.
The command will run as root at the specified time. "running for a normal user" depends on what the command is doing. Whether or not the command will send the output to the correct DISPLAY I think is the question still here. How do you know it "won't" run? Could it have run and you just see no output?
Quote:
Originally Posted by soupnsandwich View Post
What the heck is going on here?
I'm not sure. Why don't you post results from the commands:

Code:
cat /etc/crontab
crontab -l         <-as root
cat script.sh
ls -l script.sh
echo $DISPLAY      <-as root
echo $DISPLAY      <-as normaluser

Last edited by micxz; 07-27-2009 at 12:39 AM.
 
Old 07-27-2009, 01:14 AM   #28
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by soupnsandwich View Post
Ok
thanks guys for your efforts so far.
I tried everything that you guys have suggested so far with nothing actually working...I can't believe this!

Ok...how about this. What is the absolute minimum script and crontab that will work?

I replaced my script with a script that simply read "#!/bin/sh (or #!/bin/bash)
"/usr/bin/firefox"
"exit 0"
Even this didn't work!
What is the minimum for the crontab file itself?
soup (chris)
That's a good idea -- to start with something minimal. That way you can get a cron job running and then progressively add what you want until it breaks. That way you will know which are the problem commands and you can focus on them.

Running Firefox isn't exactly minimal, though.

How about
Code:
#!/bin/sh
echo XXX > /tmp/trash.$$ 2>&1
Best

Charles
 
Old 07-27-2009, 01:36 AM   #29
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by soupnsandwich View Post
Ok
thanks guys for your efforts so far.
I tried everything that you guys have suggested so far with nothing actually working...I can't believe this!

Ok...how about this. What is the absolute minimum script and crontab that will work?

I replaced my script with a script that simply read "#!/bin/sh (or #!/bin/bash)
"/usr/bin/firefox"
"exit 0"
Even this didn't work!
What is the minimum for the crontab file itself?
soup (chris)
You tried putting
Code:
echo 'DEBUG 10 (just started)' 2>/tmp/DEBUG.$$ >&2
as the first line of your script (after #!/bin/sh) and it didn't create a /tmp/DEBUG.* file? There's not much to go wrong with that echo command so, if there is no /tmp/DEBUG.* file, look for evidence of cron starting the script or not.

What's the output, for the time of interest from
Code:
cd /var/log
grep -i cron daemon.log debug dmesg kern.log messages syslog
Did you find where cron sends mail in the case of failing jobs?

Best

Charles
 
Old 07-27-2009, 08:12 AM   #30
soupnsandwich
Member
 
Registered: Jul 2009
Location: State of Rhode Island
Distribution: TBA
Posts: 34

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by micxz View Post
The command will run as root at the specified time. "running for a normal user" depends on what the command is doing. Whether or not the command will send the output to the correct DISPLAY I think is the question still here. How do you know it "won't" run? Could it have run and you just see no output?
Well...I guess it's possible but display 0 is display 0...right? I mean when I logged in as a normal user, the cron job that I set for root was pointing at the same job that ran fine as root with the "export display0:0" line at the top of the script (the one that's in /etc/cron.hourly) and as far as I knew, logging on as another user other than root is still using display 0...isn't he/it?

I'm getting the results of the debugging code that you guys gave me. I was going to set up a very minimum script and crontab file...but the one I have finally works...where as before it didn't. So do you guys think I should still, for now put aside my script and go with the one that Catkin?

Thanks again guys for all your input and time on this issue. Please note that I'm going to my shop on a different computer then the one that I'm using to test this issue so I'll have to recreate this at the shop...it may take a bit of time to get to it but I really need to resolve this problem.


I'm also going to add the debug line that was suggested into the script and see what happens.
I'm late for work...I set this up at work as soon as possible and post the results.

Thanks again guys!
soup
 
  


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 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 12:06 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