LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-07-2012, 04:13 AM   #1
mla.rue
LQ Newbie
 
Registered: Nov 2012
Posts: 2

Rep: Reputation: Disabled
a simple command in script not working:No protocol specified, Error cant open display


Hi,
Im a programm with no to little knowledge about Linux. Basicaly, we have a "linux man" here, but he is out of town for some days and thus, Im stuck with my own work.

This time I just have to programm a simple gui, that calls/starts a couple of scripts, who do all the work.

Now, when I write

Code:
eog
in the console (/bin/bash). It works (its a simple picture viewer, openSUSE 12.2).

But when I run a script that looks like this:
Code:
#/bin/bash
eog
I get the following error:
No protocol specified
Error, cant open display

When I issue the command
Code:
xhost +
in the console, the script works. However, the app isnt started from a console and do not open a console, so this is not a solution. I changed the script to
Quote:
#/bin/bash
xhost +
eog
But get the error: xhost: unable to open display ":0.0"

Of course, the script dont work when started by my app (however, when my app just executes eog, it works). The question is, what can I do?

Thanks

PS: found a lot of answers to the "no protocol specified" and "unable to open display" problem on the net, however not one helped me.
 
Old 11-07-2012, 05:37 AM   #2
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
When you simply run eog cmd from terminal, it takes default DISPLAY variable set in you shell. But when you put the same inside a shell script, it don't find the DISPLAY variable.

So once invoke echo $DISPLAY in terminal and check value of DISPLAY variable. It should be either like, localhost:0.0 or in form of homstname.somoething.something:X.X

So then define the same value of DISPLAY variable in your script, as:
#!/bin/bash
DISPLAY=<value> (Put value that you find using echo $DISPLAY)
export DISPLAY
eog


Note: Command xhost+ is used to allow other host to access your X i.e. you allowed them & they can run thier X-applications/tool on your desktop. But it don't make any sense when you're running an X-application in your own machine. Also, don't use "xhost +", as it will allow everyone to run thier X-application on your machine, instead use "xhost +<remote-hostname>" to allow only a host <hostname> to access your dekstop.

Last edited by shivaa; 11-07-2012 at 05:39 AM.
 
1 members found this post helpful.
Old 11-07-2012, 06:56 AM   #3
mla.rue
LQ Newbie
 
Registered: Nov 2012
Posts: 2

Original Poster
Rep: Reputation: Disabled
Yes thats it thanks.

Using the hints in all the other posts I found, i used DISPLAY=0:0, but this time just what echo said and its :0 and it works.

Also thanks for the clarification on the usage of xhost.
 
Old 11-07-2012, 08:18 AM   #4
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
Quote:
Yes thats it thanks.
Happy to hear this . To revert xhost changes, just invoke "xhost -" command.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
simple php ssh script does not display on browser figure20012 Programming 3 09-12-2012 10:28 AM
[SOLVED] /etc/init.d script gives "cannot open display" error rrije Linux - Software 4 11-16-2010 03:14 AM
X11 error: Can't open display - running a script from console pliqui Debian 3 10-08-2009 12:06 PM
No protocol specified Can't open display: :0.0 brandon@rhiamet.com Linux - General 3 04-06-2009 08:41 AM
Can't seem to run a simple shell script error command not found each time SimonT Linux - Newbie 5 10-29-2006 07:31 AM


All times are GMT -5. The time now is 02:02 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration