Checking whether a script can open a display?

Lennart Sorensen lsorense-1wCw9BSqJbv44Nm34jS7GywD8/FfD2ys at public.gmane.org
Tue Mar 1 22:03:04 UTC 2005


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

Lennart Sorensen
--
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