GUI program in X from script in /etc/ppp/ip-up.d?
Good day, SUSE 9.0 How do I get a GUI program (kdialog) to show on the X screen by a script in /etc/ppp/ip-up.d? It has to happen on the screen of whatever user is logged into KDE. A test script looks like this: #!/bin/bash #Test if the script is activated -- write to a file. echo "Script activated." > /root/test.txt #See what user the script is started as. echo "User: $USER" >> /root/test.txt #See what is in the DISPLAY variable. echo "Display: $DISPLAY" >> /root/test.txt #Test if kdialog can be started. echo "Result of kdialog call:" >> /root/test.txt /opt/kde3/bin/kdialog --msgbox "This is a test." 2&> /root/ test2.txt #End of script. It is the kdialog command that will not work. Both $USER and $DISPLAY are empty when the script is running, but all, except the call to kdialog, works as it is supposed to. kdialog fails with this message: "kdialog: cannot connect to X server" So I though that I just needed to give all on the local computer access to X. As the user logged in to X I have tried to export the DISPLAY variable and run xhost +local: No luck. xhost +localhost No luck. xhost + (Yes this is dangerous, but for a brief tester...) No luck. DISPLAY is set to :0.0 I also tried setting it to localhost:0.0 No luck. I tried xhost mycomputer export DISPLAY=mycomputer:0.0 No luck. I have not been able to find anything clueful to me in the SDB, the Sysadmin guide, the User guide, the list archives, or googeling. I am out of ideas. Can anyone help? Best regards Johnny :o)
On Thursday, 21 October 2004 13.51, Johnny Ernst Nielsen wrote:
Good day,
SUSE 9.0
How do I get a GUI program (kdialog) to show on the X screen by a script in /etc/ppp/ip-up.d? It has to happen on the screen of whatever user is logged into KDE.
Note: Untested I think this should work for any user other than root, but then root should never be starting X anyway USER=`last :0|grep still|awk '{print $1}'` DISPLAY=:0.0 XAUTHORITY=/home/$USER/.Xauthority /opt/kde3/bin/kdialog --msgbox "this is a test"
A test script looks like this:
#!/bin/bash
#Test if the script is activated -- write to a file. echo "Script activated." > /root/test.txt
#See what user the script is started as. echo "User: $USER" >> /root/test.txt
If this works then the user must be root, since that is the only user allowed to write to /root/
Torsdag 21 oktober 2004 14:08 kvad Anders Johansson:
On Thursday, 21 October 2004 13.51, Johnny Ernst Nielsen wrote:
Good day,
SUSE 9.0
How do I get a GUI program (kdialog) to show on the X screen by a script in /etc/ppp/ip-up.d? It has to happen on the screen of whatever user is logged into KDE.
Note: Untested
I think this should work for any user other than root, but then root should never be starting X anyway
Unfortunately, as you point out yourself, root must be the user that the system chooses to run the scripts in /etc/ppp/ip-up.d when the IP comes up. So root is the user that must display kdialog on the screen.
USER=`last :0|grep still|awk '{print $1}'` DISPLAY=:0.0 XAUTHORITY=/home/$USER/.Xauthority
Quite right -- it does not work for this situation, since it is not the las logged in user that runs the script.
/opt/kde3/bin/kdialog --msgbox "this is a test"
A test script looks like this:
#!/bin/bash
#Test if the script is activated -- write to a file. echo "Script activated." > /root/test.txt
#See what user the script is started as. echo "User: $USER" >> /root/test.txt
If this works then the user must be root, since that is the only user allowed to write to /root/
I think you are right. Thank you for your effort. :o) Any other ideas? Best regards Johnny :o)
On Thursday, 21 October 2004 15.44, Johnny Ernst Nielsen wrote:
Quite right -- it does not work for this situation, since it is not the las logged in user that runs the script.
It should work (if you put 'export' in front of DISPLAY and XAUTHORITY), I just tried it. It doesn't grab "the last logged in user", it grabs the last logged in user on :0 Try this #!/bin/bash USER=`/usr/bin/last :0|grep still|/usr/bin/awk '{print $1}'` export DISPLAY=:0.0 export XAUTHORITY=/home/$USER/.Xauthority /opt/kde3/bin/kdialog --msgbox "this is a test" I tried it and it works
Torsdag 21 oktober 2004 15:50 kvad Anders Johansson:
On Thursday, 21 October 2004 15.44, Johnny Ernst Nielsen wrote:
Quite right -- it does not work for this situation, since it is not the las logged in user that runs the script.
It should work (if you put 'export' in front of DISPLAY and XAUTHORITY), I just tried it. It doesn't grab "the last logged in user", it grabs the last logged in user on :0
Try this
#!/bin/bash
USER=`/usr/bin/last :0|grep still|/usr/bin/awk '{print $1}'` export DISPLAY=:0.0 export XAUTHORITY=/home/$USER/.Xauthority
/opt/kde3/bin/kdialog --msgbox "this is a test"
I tried it and it works
It does not work here precisely the way you suggest. It says $HOME not set. However it works if construct and export a $HOME variable like this: export HOME=/home/$USER And then the kdialog pops up on the screen. :o)))) Thank you for your help Anders. :o) Best regards Johnny :o)
Johnny Ernst Nielsen writes:
How do I get a GUI program (kdialog) to show on the X screen by a script in /etc/ppp/ip-up.d? It has to happen on the screen of whatever user is logged into KDE. ...
It is the kdialog command that will not work.
Both $USER and $DISPLAY are empty when the script is running, but all, except the call to kdialog, works as it is supposed to.
kdialog fails with this message: "kdialog: cannot connect to X server"
What you're trying to do is not quite right. The stuff that gets run in /etc/ppp/* (or for that matter, any of the rc or network startup/shutdown scripts) can happen without anyone even being logged in. A system may not even be running X at all... Their output can only be directed to the console which is the only "terminal" device that is guaranteed to be there, with or without a user actually logged in. If you want to be informed of certain events in the system while you're logged in under KDE, the proper way to do it is to write a script or program to monitor for such an event in the background, which you start up during or after you log in. It will then have the proper output context (login name, terminal, $DISPLAY environment, permissions, etc) on which to produce output. -Ti -- Ti Kan http://www.amb.org/ti Vorsprung durch Technik
Torsdag 21 oktober 2004 14:19 kvad Ti Kan:
Johnny Ernst Nielsen writes:
How do I get a GUI program (kdialog) to show on the X screen by a script in /etc/ppp/ip-up.d? It has to happen on the screen of whatever user is logged into KDE. ...
It is the kdialog command that will not work.
Both $USER and $DISPLAY are empty when the script is running, but all, except the call to kdialog, works as it is supposed to.
kdialog fails with this message: "kdialog: cannot connect to X server"
What you're trying to do is not quite right. The stuff that gets run in /etc/ppp/* (or for that matter, any of the rc or network startup/shutdown scripts) can happen without anyone even being logged in. A system may not even be running X at all... Their output can only be directed to the console which is the only "terminal" device that is guaranteed to be there, with or without a user actually logged in.
Are you saying that it is absolutely, totally, technically impossible to run a GUI application from the script the way I am trying to -- even if X IS up? On this computer, connection to the internet should not happen unless I specifically clicked the kinternet icon to make my modem dial out. As far as I understand, scripts in /etc/ppp/ip-up.d is run only when the IP comes up on a ppp connection being established, i.e. when the line is ready to transfer user information. Have I misunderstood that? If not, could you give an example of when the script in /etc/ppp/ ip-up.d would be run WITHOUT me first clicking the kinternet icon?
If you want to be informed of certain events in the system while you're logged in under KDE, the proper way to do it is to write a script or program to monitor for such an event in the background, which you start up during or after you log in. It will then have the proper output context (login name, terminal, $DISPLAY environment, permissions, etc) on which to produce output.
Event driven action was somewhat what I tried, through the use of / etc/ppp/ip.up.d. And it works, except for X. Do you have any other suggestions as to how I can make kdialog appear on the logged in user's screen when the ppp internet line is ready? Thank you for your effort. :o) Best regards Johnny :o)
Johnny Ernst Nielsen writes:
... kdialog fails with this message: "kdialog: cannot connect to X server"
What you're trying to do is not quite right. The stuff that gets run in /etc/ppp/* (or for that matter, any of the rc or network startup/shutdown scripts) can happen without anyone even being logged in. A system may not even be running X at all... Their output can only be directed to the console which is the only "terminal" device that is guaranteed to be there, with or without a user actually logged in.
Are you saying that it is absolutely, totally, technically impossible to run a GUI application from the script the way I am trying to -- even if X IS up?
No it's not technically impossible, just technically inelegant and contrary to the intentions and design of the system.
On this computer, connection to the internet should not happen unless I specifically clicked the kinternet icon to make my modem dial out. As far as I understand, scripts in /etc/ppp/ip-up.d is run only when the IP comes up on a ppp connection being established, i.e. when the line is ready to transfer user information.
Have I misunderstood that?
If not, could you give an example of when the script in /etc/ppp/ ip-up.d would be run WITHOUT me first clicking the kinternet icon?
I was speaking in general terms. A system may be set up such that it would attempt an auto-dial PPP connection when there is pending traffic. This may not be from kinternet, in fact may be from a user logged in from a non-X terminal. I always try to find the most general solution possible that would work under all circumstances. -Ti -- Ti Kan http://www.amb.org/ti Vorsprung durch Technik
participants (3)
-
Anders Johansson
-
Johnny Ernst Nielsen
-
ti@amb.org