Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Cron in X

by irah (Pilgrim)
on Sep 21, 2009 at 05:51 UTC ( [id://796488]=perlquestion: print w/replies, xml ) Need Help??

irah has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

The following Perl script has successfully executed from command line. But when I used in crontab, it is saying following error.

Xlib: connection to ":0.0" refused by server Xlib: No protocol specified couldn't connect to display ":0" at /usr/lib/perl5/Tk/MainWindow.pm line 55.

Script:

#!/usr/bin/perl use strict; use warnings; use Tk; my $mw=MainWindow->new(); $mw->withdraw(); $mw->messageBox(-icon => 'info', -message =>"It's time to leave.", -ti +tle => "Alert", -type => 'ok');

I am using Linux. Please help me to work on it.

Thanks in advance.

Replies are listed 'Best First'.
Re: Cron in X
by Anonymous Monk on Sep 21, 2009 at 06:11 UTC
Re: Cron in X
by Bloodnok (Vicar) on Sep 21, 2009 at 11:16 UTC
    What you're trying to do is not sensible.

    The error tells you that the job is attempting (and completely expectedly failing) to connect to the X server on the local machine i.e. the machine on which cron(1M) is running since cron(1M) runs its jobs non-interactively.

    A user level that continues to overstate my experience :-))
Re: Cron in X
by lakshmananindia (Chaplain) on Sep 21, 2009 at 07:26 UTC

    Set the DISPLAY environment variable to your environment. Also try xhost + (to disable the access control)

    --Lakshmanan G.

    The great pleasure in my life is doing what people say you cannot do.


      While technically correct, xhost+ also opens your system up to any X client that wants to connect to your machine. How about a transparent, borderless, sticks to the top of the window stack client that does nothing but record events and pass them on to the underlying windows.

      At least use xhost +otherhostname or xhost +localhost. See this example documentation for details.

      --MidLifeXis

      Please consider supporting my wife as she walks in the 2009 Alzheimer's Walk.

      I did setting DISPLAY environment variable and xhost +. It's not working.

        My guess is that your X server isn't configured to listen for TCP connections (seems to be the default on modern Linux distros), and the cron job is missing something (permissions? environment variable?) to allow it to connect over unix domain sockets. xhost + won't help in that case, you need to either re-enable the tcp listening on the X server (varies by distro, look for "-nolisten tcp" in the X11 startup args) or figure out how to get the client to use unix domain sockets successfully from the cron job.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://796488]
Approved by planetscape
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-03-29 06:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found