Checking whether a script can open a display?

John Vetterli jvetterli-zC6tqtfhjqE at public.gmane.org
Wed Mar 2 00:04:22 UTC 2005


On Tue, 1 Mar 2005, William O'Higgins wrote:
> On Tue, Mar 01, 2005 at 05:36:31PM -0500, William Park wrote:
>> 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?
>>>> 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.
> This is, indeed, the problem - cron runs with a very limited
> $ENVIRONMENT.  If not for that I'm sure that it would work.

You could try something along the lines of:
 	lsof | grep -- '/tmp/\.X11-unix/X0'

But if the real problem is getting useless emails from cron, try 
redirecting the output of your script (stdout and stderr) to /dev/null. 
That should suppress any email notices.

JV
--
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