LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Attempting to open Perl/Tk window by anacron (https://www.linuxquestions.org/questions/linux-newbie-8/attempting-to-open-perl-tk-window-by-anacron-934461/)

kaza 03-14-2012 02:42 PM

Attempting to open Perl/Tk window by anacron
 
Hello,

I'm attempting to use "anacron" to start a Perl/Tk script
which I wrote "remind_to_backup". When I'm starting it from
a terminal (as root) - it opens OK. But when I didn't see it open
by "anacron" I looked in "/var/spool/mail/root" and saw the following
message:

Code:

From root@localhost.localdomain  Mon Mar 12 14:31:02 2012
Return-Path: <root@localhost.localdomain>
Received: from localhost.localdomain (localhost.localdomain [127.0.0.1])
        by localhost.localdomain (8.14.4/8.14.4) with ESMTP id q2CCV226005184
        for <root@localhost.localdomain>; Mon, 12 Mar 2012 14:31:02 +0200
Received: (from root@localhost)
        by localhost.localdomain (8.14.4/8.14.4/Submit) id q2CCV1DY005183
        for root; Mon, 12 Mar 2012 14:31:02 +0200
Date: Mon, 12 Mar 2012 14:31:02 +0200
Message-Id: <201203121231.q2CCV1DY005183@localhost.localdomain>
From: Anacron <root@localhost.localdomain>
To: root@localhost.localdomain
Content-Type: text/plain; charset="ANSI_X3.4-1968"
Subject: Anacron job 'remind_to_backup' on localhost.localdomain

No protocol specified
couldn't connect to display ":0" at /usr/lib64/perl5/Tk/MainWindow.pm line 55.
MainWindow->new() at /root/bin/remind_to_backup line 23

After searching the net for this error I understand that the issue
here is lack of permission for "root" to access the X windows
server (If I understand correctly).

What I don't quite understand is why I can open this window
from an ordinary root shell but "anacron" can't open it?

The shell I prefare to use is "tcsh", the appropriate line
in /etc/passwd file is:

root:x:0:0:root:/root:/bin/tcsh


which is different from the original shell (bash) after the
installation (FC14). How can I know, in what shell the "anacron"
runs? What's the difference (from the standpoint of X server
access) between programs called by "anacron" and same programs
called from the command line (by root)?
While searching the net I saw suggestions like:

xhost +root

or

xhost +localdomain

but I have none of such commands in my /root/.tcshrc file
but still, I can open the Perl/Tk window as root from the command line.

TIA for any ideas,
kaza.

Tinkster 03-14-2012 04:22 PM

This teaches us a few things.

Firstly: you seem to run your machine as root; bad idea ;}

Secondly: you have bad taste in shells... (sorry, couldn't resist).

Anyway, to solve your problem (I don't think it's shell related) just issue
in the running X-session: xhost +localhost

And in the cron file prepend the bit that starts your Tk script w/ DISPLAY=:0.0



Cheers,
Tink

kaza 03-15-2012 12:06 PM

Hi Tinkster,

thanks for the reply.

I don't run as root usually, I login as other user. But to test this
script I first did "su -" since I wanted to test as close as possible to the
real situation when the "anacron" will call it.

I added

xhost +localhost > /dev/null

to the /root/.tcshrc

and changed the line in /etc/anacrontab from:

7 50 remind_to_backup env DISPLAY=:0 nice remind_to_backup


to

7 50 remind_to_backup env DISPLAY=:0.0; nice remind_to_backup

Now I'll wait few days to see what the result will be.

Thanks,

Tinkster 03-15-2012 02:17 PM

Wait a sec ... so, which user are you running your X-session as?

kaza 03-16-2012 05:14 PM

Hi Tinkster,

During boot at login prompt I log in as a normal user,
when I run "ps" I see that gnome-session is run by my login user.
I checked "ps | grep root" and as far as I can tell I only
saw low level or hardware related processes run by root.

Does it adds more insight as to the original problem cause?

TIA,
kaza.

Tinkster 03-16-2012 10:55 PM

Nope. It means that you need to do the xhost +localhost from your normal
user account; as an aside, that most likely won't work from your ~/.profile/
~/.tcshrc because xhost needs to be run from within X.
Find out whether Gnome can run scripts and such during login, and add it
to that.



Cheers,
Tink


All times are GMT -5. The time now is 10:55 PM.