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 09-03-2009, 12:34 PM   #1
emkersyt
LQ Newbie
 
Registered: Sep 2009
Posts: 4

Rep: Reputation: 0
gtk notification from root cronjob


Hi, can anybody tell me if it is possible to configure a cronjob from root level so that it uses GTK applications (like gxmessage in my case) to give out notifications on the screen?
On my Debian machine the user can evoke these notifications from the script executed by his crontab but the same script executed from root's crontab doesn't bring up these messages. The scripts works, though, just the gxmessage part won't work.
I need the root permissions because the script is meant to be a system admin job with a final shutdown command in case the battery runs low.
I suspect that the script doesn't work because root in some cases is not "allowed" to run graphical apps for security reasons. Is that the case here?

Last edited by XavierP; 09-03-2009 at 05:11 PM. Reason: Moved over to Software
 
Old 09-03-2009, 05:28 PM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599
Quote:
Originally Posted by emkersyt View Post
but the same script executed from root's crontab doesn't bring up these messages. The scripts works, though, just the gxmessage part won't work.
By default cronjobs will report errors to a preconfigured (MAILTO) or default (crontab owner) email address. Looking for clues in returned messages might give a clue. Common pitfalls are a missing DISPLAY variable or Xauth auth.
 
Old 09-03-2009, 08:32 PM   #3
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Buster (Fluxbox WM)
Posts: 1,391
Blog Entries: 52

Rep: Reputation: 360Reputation: 360Reputation: 360Reputation: 360
Perhaps you can you do something like:

Code:
su -c "DISPLAY=:0.0 gxmessage 'abc'" adminuser
 
Old 09-04-2009, 05:54 PM   #4
emkersyt
LQ Newbie
 
Registered: Sep 2009
Posts: 4

Original Poster
Rep: Reputation: 0
I actually can execute the script as root and it then also pops up the gxmessage notification. I tried defining the DISPLAY variable in the script as well as in the crontab. The same with the Xauthority variable.
I think I checked out all possible combinations. No results.
Note that the only thing which doesn't work is executing gxmessage from the crontab as root. It works as user, and it works as root from the command line. It really puzzles me, what is the difference between executing a script from the CL or from the crontab apart from the Display and xauthority?
About the error reports: I saw that there is no mail for root, I never configured it but I thought it would work automatically. The user gets mail, though. With Debian, by default, do I have to configure the mail system for root in order to have it working? Seems strange to me ...
 
Old 09-04-2009, 07:26 PM   #5
emkersyt
LQ Newbie
 
Registered: Sep 2009
Posts: 4

Original Poster
Rep: Reputation: 0
I tried the suggestion nonsignal brought up:

Quote:
*/1 * * * * /bin/su -c "DISPLAY=:0.0 /usr/local/sbin/batpowershutdown" myuser
That is a root crontab entry. With that the notification gets launched, but, of course, the shutdown command will
fail. I am kind of abusing my user for the gxmessage notification. If I change "myuser" for "root" again it doesn't work.
Btw, the scripts has the correct permissions set, it is using the commands with full path.
 
Old 09-06-2009, 02:44 PM   #6
emkersyt
LQ Newbie
 
Registered: Sep 2009
Posts: 4

Original Poster
Rep: Reputation: 0
Ok, after another night fiddling around I found what was the problem.
It was actually the Xauthority as UnSpawn suggested. I tried that before already but apparently I did something wrong.
Anyway, it looks like the issue with gtk and root cronjobs is that root can't effectuate graphical notifications because it has no Xauthority file in /root. Hence X will negate access here. I guess cronjobs run in a very different environment than root from the CL. Otherwise I can't explain why the same scripts works from the CL and not from the crontab.
Nevermind, the solution here was using the Xauthority from the normal user by exporting it just before issuing the gxmessage command.
Hope that will be a help for someone having a similar problem one day.

Last edited by emkersyt; 09-06-2009 at 03:13 PM.
 
  


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
[SOLVED] Cronjob: Could not authenticate PAM user ... Authentication failure (for root?!?) JZL240I-U Linux - Security 11 03-14-2019 01:05 PM
Few questions about Nagios - reboot notification, value=x notification. marccmile Linux - Software 5 06-04-2009 06:44 PM
Cronjob for Root ryanlum Linux - Newbie 4 06-25-2008 03:45 AM
reaching to the notification area with gtk atokatli Programming 1 07-01-2005 12:35 PM
root window background through gtk? jpbarto Programming 0 05-22-2004 09:20 PM

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

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