Checking whether a script can open a display?
William Park
opengeometry-FFYn/CNdgSA at public.gmane.org
Tue Mar 1 22:36:31 UTC 2005
On Tue, Mar 01, 2005 at 05:03:04PM -0500, Lennart Sorensen wrote:
> On Tue, Mar 01, 2005 at 04:52:29PM -0500, William O'Higgins wrote:
> > I use a cron job to update the backdrop (root window) of my window
> > manager. Sometimes I am not running X, however, and then my mail box
> > fills up with cron telling me that it cannot open display :0.0. Is
> > there a way I can test whether I can open that display so I can quit
> > cleanly?
> >
> > The reason that this has come up is that I have had a few reboots in the
> > past couple of months - always when I am not at home. The only thing in
> > /var/log/messages is this:
> >
> > Mar 1 14:41:56 hostname -- MARK --
> >
> > # these happen every twenty minutes, like clockwork ;-) until I get a
> > # message like this:
> >
> > Mar 1 14:59:09 hostname syslogd 1.4.1#16: restart.
> >
> > And then there are all the ramblings of a reboot. The first I hear
> > about it is if I was logged on via ssh and my terminal hangs, or I
> > see the emails from cron about being unable to open the display ('cause
> > X doesn't run by default).
> >
> > Any pointers would be appreciated. Thanks.
>
> if [ -z "$DISPLAY" ]; then
> echo "No display";
> else
> echo "Do something";
> fi
Hmm... Checking DISPLAY works if you're in Xterm shell session, say
from ~/.profile. But, I don't think Cron sees or care about DISPLAY
environment variable. In fact, Cron by design runs with minimum set of
environment variables.
Try 'ps -C X' or something.
By the way, why would Cron cause reboot of your computer if X is not
running?
--
William Park <opengeometry-FFYn/CNdgSA at public.gmane.org>, Toronto, Canada
Slackware Linux -- because I can type.
--
The Toronto Linux Users Group. Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml
More information about the Legacy
mailing list