Jump to content

Make scripts executable from GUI? [solved]


Recommended Posts

Well, I guess the title says it all. I need to use shell commands to start my modem, so I'm thinking of writing a script to automate the three commands this involves. It's my first attempt at such a thing in Linux.

 

So when I have it written, and sitting on my desktop, is there a way I can configure it so that it just runs when I double-click it?

 

Also, the commands are privileged, so can the script also perform 'su' automatically by some command that includes the root password? Or is there a safer, permission-based way of setting-up the script so that this is possible?

 

Any ideas or pointers would be ... well, great, ya know.

 

 

Edit: moved from Software by spinynorman

Edited by Havin_it
Link to comment
Share on other sites

If you right click on it, you should get some options - one of which I seem to remember is something like - run in a terminal. This might make it easier to run with a double click.

 

As far as running commands as root - take a look at sudo. This allows you to specify commands that can be run as root, by a normal user (if that makes sense) without the need for a password - making it easier to run those scripts from a script

Link to comment
Share on other sites

phuni is right about sudo, but getting it to run by double clicking is easy,

 

All you need to do, is open up a console, navigate to the directory where the shel script is, and enter

chmod -x nameofscript.sh

 

If that doesn't work, tryit again as root. I KNOW that will work.

Link to comment
Share on other sites

Thanks guys. Just been checking out sudo (or more specifically visudo) and it's driving me frickin' nuts already.

 

I think the syntax for the powers i want should be

 

havinit ALL=NOPASSWD: (root) ALL

 

But apparently not! So I guess this is now a plea for some sudoers knowledge. The manpages are not really great on this subject! I'm currently doing these edits in Kwrite because I couldn't make head or tail of visudo's control syntax.

 

(I need the NOPASSWD bit so I can hopefully use these commands in a script)

Link to comment
Share on other sites

Please don't try and allow your mortal to run any command as root - it's a BAD idea!!

 

All the information you need should be in man sudoers, something like:

 

havinit localhost = NOPASSWD: /first/command, /second/command

 

should do it

Edited by Qchem
Link to comment
Share on other sites

I could be totally wrong, because I'm no security person, but wouldn't it be better to just make the actual script setuid root, so that the actual script runs as root, but give his user permission to run it?

 

Like this

 

chown root:root /path/to/script

chmod +s /path/to/script

chmod 0755 /path/to/script

 

Please correct me if I'm wrong. I remember reading a post about allowing normal users the ability to start the internet connection by doing something similar to pppd and/or /dev/modem.

Link to comment
Share on other sites

Thanks guys - yes, I see the point about not making myself able to SUDO everything with no password, so I'm reverting to the chmod method. The wierd thing is it doesn't seem to work as I'd hoped.

 

In the scope of (having done the chmods on the programs in question) trying to run the commands as myself, what's now happening is the commands appear to return without error but are not actually succeeding - probably why the non-sudo script I wrote doesn't seem to succeed.

 

The commands are:

/usr/sbin/modem_run -m -f /usr/share/speedtouch/mgmt.o

/usr/sbin/pppd call adsl

sbin/ifconfig

 

I'm still able to run these as root (and without the paths), but as myself, the ifconfig returns only eth0 and lo, not ppp0 as intended. modem_run appears to work, as the modem's LEDs cycle in the normal way, so I'm assuming pppd is the problem. Do I need to chmod the peer file for adsl as well? As it's basically a config file I didn't think it would need to be executable.

Link to comment
Share on other sites

chmod +s /usr/sbin/modem_run

chmod +s /usr/sbin/pppd

chmod 0755 /etc/ppp/peers/adsl

 

The last one may possibly work with 0744

 

You will still probably have to use the whole path for each in your script, because /sbin is not in your normal user's path (for good reason) and I don't think /usr/sbin is either. With all of this, I don't think you'll need to make the owner of your script root nor will you have to chmod +s your script.

Edited by Steve Scrimpshire
Link to comment
Share on other sites

Thanks, I will try chmodding adsl as well. BTW, is the 'in your path' thing really such a hacker-beater? If my user was possessed by evil (well, not by me anyway), wouldn't it just take a few educated guesses on system topology to locate the path and use it if permitted?

 

Just a thought - forgive me if I'm missing something obvious, us noobs usually do!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...