[SOLVED] Find out if X11 is running from within perl OR bash script
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Heh, woulda been MUCH faster had I not been in the midst of debugging a weird window-manager bug which initially prevented me from getting to this thread!
Generally speaking, it's not good to rely on certain process name. I would rather try to run a program which requires X and check whether it fails or not because of lack of X.
...
Typically under X DISPLAY environment variable is set. It is set even when, say, X tunneling 'ssh' connection is used.
You need X to be running on the host pointed to by $DISPLAY. If I telnet to some arbitrary host, check using ps whether it has an X server running, and then try to launch imagemagick, I will invariably simply fail to accomplish what I need (assuming I want to actually see the X rendering, not always the case).
Really, there is no sure-fire way to accomplish what you want, and in the absence of X, most X applications will simply write a brief message to stderr, and set their exit code to non-zero (imagemagick does on my system right now). Since you must have planned to handle the possibility of not having an X server anyway, why not just let the application fail to launch and go on with whatever corrective action you were planning?
--- rod.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339
Original Poster
Rep:
This is what i have so far.
Code:
convert _temp.bmp $filename
}
function info {
identify $filename
}
function woc {
cp $filename $newname
filename=$newname
}
while [ 1 ]
do
echo -n ">"
read what
case $what in
load)
echo Enter filename:
read filename
if [ -e "$filename" ]
then
echo File loaded
else
echo FILE NOT FOUND!
fi
;;
view)
view;;
resize)
echo Enter the new size in the form of n1xn2 where n1 is the X size and n2 is the Y
size:
read size
resize;;
rotate)
echo Enter the angle:
read size
rotate;;
colors)
echo Enter amount of colors:
read size
colors;;
brightness)
read size
brightness;;
info)
info;;
copy)
echo Enter new name:
read newname
woc;;
esac
done
rm _temp.bmp
end
Something like this wil work better:
"if [ -n $DISPLAY ]"
Simply looking to see if X is running may not work -what if the user running the script is ot the one running X?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.