siple bash script for launching application in KDE

Hello,

I have written script for launching
opnevpn. It works in terminal (konsole)
or by launching in midnight commander.
The issue:
I want to have a file/link that i can click on
(i use KDE just as link icon) so that it
would open terminal and execute the script.

I have tried: to make *.sh file, mark
it as executable and click in dolphin
but it results in nothing.

Where am i wrong here?

the script:


#!/bin/bash
clear
echo "Hello, starting up openvpn script"
PTH=/etc/init.d/
cd $PTH
echo "running openvpn START:"
echo
sudo ./openvpn start
echo

When you run it from KDE, there is no terminal from which sudo can read the password. Try replacing sudo with kdesu which will pop up a dialog to collect the password.

Just for your information. There is no need to give it a name ending in* .sh* apart from it being an information to you that you think it is a shell script of some kind.

The fact that it is executable lets the system try to load it when you call it as executable in a command and the fact that the first line contains #!/bin/bash makes that it does not load the file, but does load */bin/bash *offering it your file as the script to be executed.

Thanks guys for your input!

concerning replacing sudo with kdesu:
good thing that now i get console popup,
not so good that i still don’t get script to run in
it at once. I get: Command ‘./openvpn ‘start’’ not found.
if i run it in konsole or mc i get same message…

For admin, thanks for tip. I’m really new in scripting (obviuosly :))

Do not use

./openvpn start

but

/etc/init.d/openvpn start

(and then you can remove the PTH and cd lines).
The kdesu will change your working directory to somewhere else. Better use an absolut instead of a relative path, no suprises possible then.

cheers,

when i changed to absolute path
i was prompted for root pass but
further on I was not prompted for
user and pass for openvpn as i would
by running “the original script” in konsole alone.

I checked in system activity and openvpn was
running under kdesu … (but no network connection)

One more thing when i type kdesu /etc/init.d/openvpn start
in konsole, openvpn does not ask for user and pass
in contrast to sudo /etc/init.d/openvpn start

So launching works but no user or pass prompt…
Any ideas?

What I did was explaining you how to get your* init.d* script running as root from a normal GUI login (which is normaly only done during testing of a deamon/tool)

I do not know what that script is supposed to do. But as* /etc/init.d* contains scripts that are to be run, by root and in the background, at boot/shut-down of the system, I never came to my mind that such a script could ever have something interactive, let alone a userid/password conversation.

May be you should go back to the drawing table to consider what your real problem is. And also to consider if you want ask on the forums for help on that real problem.

Done no checking but I have a crude gksu script, mine takes the parameter to run.

I would thought you need to approach this similar.

xterm -hold -geom 60x5 -T "xdg-su: $cmd" -e su -c "echo this ; bash"

But the above seems hackish to me it may work for you(Or a variant). I can’t actually try to see whether it would then prompt and allow you to input the pw and user.

This is using xterm but many of the other consoles have execute command I used the -hold flag to keep it open you may find this is not necessary and then it continues into bash.

Then the other way to tackle this and IMO cleaner would be to look at creating a .desktop file(Menu editor should allow or context menu create app launcher). Then storing it under the user in this you would have the command and start in terminal checked.

Thanks for reply and suggestions,
next time i will defently consider whether
to bother forum with obscure questions.

the script was supposed to open konsole
or other way of dialog run openvpn asking me user and pass
and open “tap0” (connect). It is all doable by manually opening konsole
typing sudo /etc/init.d/openvpn start.

I thought I could write the script file and just click on it to skip manual
launching and typing…
as lazy as that…

You didn’t tell us that your openvpn’s startup required manual entry of a user and password in addition to the sudo password. Interactive input is not normally the case for service scripts put in /etc/init.d because then they would interrupt the boot sequence. kdesu only handles the su part and I thought that was your only drawback.

openvpn can run as both a server and a client. You did not tell us you were using it as a client. If you are using it as a client, /etc/init.d/openvpn is the wrong place to start a client.

If you want to start openvpn as a client, and type in a username and password, you can do from a GUI icon by starting openvpn inside a konsole (see the -e option). Knetworkmanager is also supposed to handle openvpn connections but I don’t use that so I don’t know how well it works.

I think there is no doubt that it can be done, but you did not tell us what you wanted to achieve. You started meddling arouund with what you thought to be a solution. And then got stuck somewhere. Then you came here with only the point where you got stuck. How could we ever see your real problem when you hide it?

Let the fact that a lot of people do this be a relieve to you :slight_smile:

To ken_yap,

Thanks for suggestion
I can’t get Knetworkmanager(KNM) configured right.
I have config file from IT service which is not read by KNM
I tried some how read setting from config file but no luck
in applying them.