Checking whether a script can open a display?
Walter Dnes
waltdnes-SLHPyeZ9y/tg9hUCZPvPmw at public.gmane.org
Wed Mar 2 01:33:48 UTC 2005
On Tue, Mar 01, 2005 at 05:03:04PM -0500, Lennart Sorensen wrote
> if [ -z "$DISPLAY" ]; then
> echo "No display";
> else
> echo "Do something";
> fi
That may not work. $DISPLAY is an environmental variable. On my
system it gets set in .bashrc and should remain set even if X doesn't
start. Here's what I would suggest. Execute...
ps -e
when X is running. Here are some things that will always show up on
*MY* system when X is running...
8739 tty10 00:00:00 startx
8750 tty10 00:00:00 xinit
8751 ? 00:17:07 X
8769 tty10 00:00:22 blackbox
8770 tty10 00:01:26 bbkeys
8771 tty10 00:00:00 xterm
8773 tty10 00:05:08 fbpanel
So I would do something like...
#!/bin/bash
ps_output=`ps -e | grep " xinit"`
if [ ${#ps_output} -gt 2 ]; then
echo "X is running. On with the show."
else
echo "X is not running. Now what?"
fi
Replace the "echo" commands with real stuff. Your system will likely
have a different set of "guaranteed" programs that will be running
whenever X runs. So be prepared to adjust as necessary.
--
Walter Dnes <waltdnes-SLHPyeZ9y/tg9hUCZPvPmw at public.gmane.org>
An infinite number of monkeys pounding away on keyboards will
eventually produce a report showing that Windows is more secure,
and has a lower TCO, than linux.
--
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