Page 1 of 1

help with a shell script, please

Posted: Fri Feb 01, 2008 3:57 pm
by karl
Hi

I am currently starting a program from within the terminal, by typing sudo and then the path and name of the program and then start.

If I understand correctly, I should be able to put this single line into gedit, give a .sh extension and run the program by double clicking.

I did try this and it didn't work, I have realised that when I type into terminal, I am prompted for my password and am guessing this is why it doesn't work.

Can anyone suggest a way to overcome this please?

Re: help with a shell script, please

Posted: Fri Feb 01, 2008 5:04 pm
by karl
Wow, that was quick, thank you.

I'm giving it a try now.

Re: help with a shell script, please

Posted: Fri Feb 01, 2008 5:22 pm
by karl
Sorry, I think I'm being particularyl dim. I can't get it to work
paradigmX wrote:file extension doesn't matter, you don't even need one
Okay, the file is now called startxampp with no extension.
paradigmX wrote: from what I'm hearing, you have 3 problems:

1: your first line has to be a call to the Bash interpretter and should be like this

Code: Select all

#!/bin/bash


3: you either have to have it in a directory the kernel would recognise as for executables or use a ./ in front of your file.
ie.

Code: Select all

./<filename>
The content of the file is

Code: Select all

#! /bin/bash
cd /opt/lampp
./lampp start
I did try without the 'cd' part and just ./opt/lampp/lampp start and also without the '.' but none of them worked.
paradigmX wrote: 2: you need to set the permissions on the file to executable, you can do this at the command line by typing

Code: Select all

chmod +x <filename>
I did this in terminal - it only needs to be done once and not in the file, is that correct?

Thanks for your help, sorry I'm not getting it.

Re: help with a shell script, please

Posted: Sat Feb 02, 2008 1:14 pm
by cmost
Forgive me for wandering in in the middle of this discussion, but what exactly are you trying to do? I've looked at the contents of your file, and I'm not surprised it didn't work.

#! /bin/bash
cd /opt/lampp
./lampp start

Is incorrect way to start a program the way you intend. If the program is already in your path, or to say in a more simple way: if you can start the program by simply typing its name in an ALT+F3 run dialog then your script should be formatted the same way. Here's an example.

I like to delay the start of avant-window-navigator on my system until everything else has loaded. Here's my shell script to do that:
---------------------------------------
#!/bin/bash
killall avant-window-navigator
sleep 45
avant-window-navigator
---------------------------------------

As is standard, the first line calls the Bash interpretor; the second line kills any previous instance of the program; the third line causes the script to pause for 45 seconds and finally, the last line executes the program. Notice, I don't have the path of the avant-window-navigator; it's not needed because this program is already in my path.

Here's another example:
---------------------------------------
#!/bin/bash
export AWT_TOOLKIT=MToolkit
export HOSTNAME=localhost
/usr/lib/frostwire/runFrostwire.sh
---------------------------------------

In this case, I'm also exporting some variables. Note I needed to specify the patch to the runFrostwire.sh script because this isn't in my path normally.

Please provide me with a more detailed explanation of what you're trying to launch with the script and perhaps we can build a better script to do exactly what you want. Good luck.

Re: help with a shell script, please

Posted: Sat Feb 02, 2008 1:29 pm
by karl
Thanks

I'm trying to run Xampp which is an all-in-one program for php/mysql/apache.

to run it from terminal, I type

sudo /opt/lampp/lampp start

I have no idea if /opt is in my path.

Re: help with a shell script, please

Posted: Sat Feb 02, 2008 2:00 pm
by cmost
Since you start the program by specifying its path, then try this to make a shell script:

1. Open gedit and paste the following:

#!/bin/bash
/opt/lampp/lampp start

2. Save the file as "start_lampp" (or whatever you like)
3. Right-click on the file; select the 'Permissions' tab and tick the check-boxes for 'execute' for Owner, Group & Others.
4. Next, I'm assuming you're trying to make a handy desktop or panel shortcut. Right-click on your desktop and select 'Create Launcher'
a. Select Type = Application
b. Name = Start lampp (or whatever you like)
c. Command = gksu /path/to/start_lampp
d. Comment = Start lampp application (or whatever you like)
e. Click the large icon button to choose a pleasing icon, or keep the default one.
f. Click 'OK' to save and close. You should now have a new icon on your desktop.
5. Click the new icon; you should be asked for your root password and then the lampp application should start normally.

Let me know if this works. :-)

Re: help with a shell script, please

Posted: Sat Feb 02, 2008 3:42 pm
by karl
Works a treat

Thank you very much :D