LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-14-2012, 02:42 PM   #1
kaza
Member
 
Registered: Apr 2010
Distribution: FC17
Posts: 343

Rep: Reputation: 2
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.
 
Old 03-14-2012, 04:22 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
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
 
Old 03-15-2012, 12:06 PM   #3
kaza
Member
 
Registered: Apr 2010
Distribution: FC17
Posts: 343

Original Poster
Rep: Reputation: 2
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,
 
Old 03-15-2012, 02:17 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Wait a sec ... so, which user are you running your X-session as?
 
Old 03-16-2012, 05:14 PM   #5
kaza
Member
 
Registered: Apr 2010
Distribution: FC17
Posts: 343

Original Poster
Rep: Reputation: 2
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.
 
Old 03-16-2012, 10:55 PM   #6
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
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
 
  


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
Attempting installing Perl module Gimp::Fu - dependecies problem kaza Linux - Software 3 10-30-2010 01:48 AM
[SOLVED] perl script tp open an xterm window and run a command. casperdaghost Linux - Newbie 2 07-25-2010 02:49 AM
[SOLVED] Firefox 2.0.0.20 - can't open second window/dupe a tab to a new window. Used to work. GrapefruiTgirl Linux - Desktop 4 06-24-2009 08:27 PM
how to open a browser window using perl iceman_san Linux - Newbie 3 08-28-2007 09:05 AM
Attempting perl poetry chr15t0 Programming 4 10-16-2003 11:15 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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