Boston Linux & Unix (BLU) Home | Calendar | Mail Lists | List Archives | Desktop SIG | Hardware Hacking SIG
Wiki | Flickr | PicasaWeb | Video | Maps & Directions | Installfests | Keysignings
Linux Cafe | Meeting Notes | Linux Links | Bling | About BLU

BLU Discuss list archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Discuss] Most reliable method to test if x server is running in a Bourne Shell script



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Testing for the DISPLAY environment variable is unreliable because some
clients, such as Putty with X forwarding will set up DISPLAY even though
no x server is running. One way is to run an X application and test the
return code, but you would want that X app to return either success or
failure, but otherwise do nothing. IBM mainframes have a program,
IEFBR14 that simply returns (It is 1 line of code to branch to register 14).
Basically, what I want to do is something like:
#!/bin/sh
# The next line will execute in sh but not in tcl \
testxworking
# \
if [ $? = 0 ];then
# The backslash makes the next line a comment in Tcl \
exec wish "$0" ${1+"$@"}
# \
else
# \
 -- call a command line script
# \
exit
# \
fi
- ---

Basically, what I want to do is to bring up a GUI if X is available, or
simply run from the command line if not. BASH will execute the lines
that do not begin with a #, tcl (and wish) will not execute lines
preceeded by a '# \'.
But, the real issue is the line: testxworking. I want a short program
that returns 0 if an x server is present, and non-zero if not.



- -- 
Jerry Feldman <gaf at blu.org>
Boston Linux and Unix
PGP key id:3BC1EB90
PGP Key fingerprint: 49E2 C52A FC5A A31F 8D66  C0AF 7CEA 30FC 3BC1 EB90
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEVAwUBTmkYonzqMPw7weuQAQL29gf/UbicA3/IrdAB5v2mYcO6pj+CklU6F/sB
u6m/RqWUW4ihgeSVZ+aZOXoxZ/+t+us6jgcS11RTDbKTd5Qt/7mgiN7XBWXKbuVW
OW6AjvEgdcPWLj6FnsRHDM2vk9tioMsYWXg51CV3uxNcMbHJ7dAJhsixM2r3mkBn
wviTnp2dpGNZUmqrDKd8Kn6UHBZBGWYFRJjTzhU8Ey2noW/97hEgZoKGIFU6nnYy
KMGuwI0zBRCBk0lt7vfx5q0sNdVpUMmmxAFcGEqfwk++6HYNPDax3jYsm5/At3jz
R31iX0Q0O+MXOcv0BZDZBJRZIqZ1rfRG/JOUSwyVB3vouFBtCRMREA==
=2bti
-----END PGP SIGNATURE-----




BLU is a member of BostonUserGroups
BLU is a member of BostonUserGroups
We also thank MIT for the use of their facilities.

Valid HTML 4.01! Valid CSS!



Boston Linux & Unix / webmaster@blu.org