help with a shell script, please

All Gurus once were Newbies
Forum rules
There are no such things as "stupid" questions. However if you think your question is a bit stupid, then this is the right place for you to post it. Please stick to easy to-the-point questions that you feel people can answer fast. For long and complicated questions prefer the other forums within the support section.
Before you post please read this

help with a shell script, please

Postby karl on Fri Feb 01, 2008 3:57 pm

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?
karl
Level 1
Level 1
 
Posts: 20
Joined: Tue Oct 02, 2007 3:36 pm
Location: Torquay, Devon, England

Linux Mint is funded by ads and donations.
 

Re: help with a shell script, please

Postby paradigmX on Fri Feb 01, 2008 4:11 pm

file extension doesn't matter, you don't even need one

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


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>


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>
paradigmX
Level 1
Level 1
 
Posts: 14
Joined: Fri Jan 18, 2008 12:53 pm

Re: help with a shell script, please

Postby karl on Fri Feb 01, 2008 5:04 pm

Wow, that was quick, thank you.

I'm giving it a try now.
karl
Level 1
Level 1
 
Posts: 20
Joined: Tue Oct 02, 2007 3:36 pm
Location: Torquay, Devon, England

Re: help with a shell script, please

Postby karl on Fri Feb 01, 2008 5:22 pm

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.
karl
Level 1
Level 1
 
Posts: 20
Joined: Tue Oct 02, 2007 3:36 pm
Location: Torquay, Devon, England

Re: help with a shell script, please

Postby cmost on Sat Feb 02, 2008 1:14 pm

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.
cmost
Level 4
Level 4
 
Posts: 398
Joined: Tue Sep 18, 2007 7:36 am
Location: Newport, Kentucky

Re: help with a shell script, please

Postby karl on Sat Feb 02, 2008 1:29 pm

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.
karl
Level 1
Level 1
 
Posts: 20
Joined: Tue Oct 02, 2007 3:36 pm
Location: Torquay, Devon, England

Re: help with a shell script, please

Postby cmost on Sat Feb 02, 2008 2:00 pm

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. :-)
cmost
Level 4
Level 4
 
Posts: 398
Joined: Tue Sep 18, 2007 7:36 am
Location: Newport, Kentucky

Re: help with a shell script, please

Postby karl on Sat Feb 02, 2008 3:42 pm

Works a treat

Thank you very much :D
karl
Level 1
Level 1
 
Posts: 20
Joined: Tue Oct 02, 2007 3:36 pm
Location: Torquay, Devon, England

Linux Mint is funded by ads and donations.
 

Return to Newbie Questions

Who is online

Users browsing this forum: Bing [Bot], GenChildren, Mute Ant, sprintcowboy and 30 guests