ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
My (mis)understanding of running twocommandsin one scriptfile is;
Simplest: Put each command on its own line and the shell will run them one after the other.
Or put the commands on the same line, separated with a semicolon.
I think I understand commands can be kind of ran together using pipes and if then stuff?
I have only tried the simplest methods so far, but cant figure out why they aren't working, like I thought they would, from what I have been reading.
What I'm trying to do, is an insmod for my ethernet driver, followed by dhclient eth0 in one file, to be executed by clicking a shortcut on my desktop.
It seems I will have to learn how to allow a regular user to to run these commands, but first I guess I should be able to run the script from the command line as root, but I cant make even that happen yet.
When I put the insmod command inafile and make the file executable, it works as I expect, I can just enter the name of the file at the command prompt and the insmod command runs and loads the driver for eth0.
Same for the command dhclient eth0 when it is the only command in the file.
But when I put both commandsin the same file and try to run them by executing the file, only insmod works, dhclient eth0 does not work.It doesnt matter what command I put first in the file.
Thank you poison,
Now the script runs fine when I'm logged as su.
I have chmod' the scriptfile,and the file tries to open when I try to run it as a regular user, but I get the error " insmod command not found".
something tells me I shouldn't try to change permissions on insmod so that a regular user can run it.
What is a good way to make this work, to be able to run insmod and dhclient as a regular user?
sorry ^^
I didn't look to close at your post.... a shell script begins with the so called shebang line:
Code:
#!/bin/bash
this points to the location of the interpreter you want to use...and has to be at the VERY beginning of the file....in this case you use bash....
then you can add the commands you wish to issue...one line by another...
Code:
modprobe whatever
dhclient eth0
to make it executable,
chmod a+x <scriptname>
if it contains command which can onlly be issued by root, you have to set the uid or execute it as root...
to set the uid
chmod u+s <scriptname>
when you log out the root command now, you should be able to use it as plain user...
please notice that setting the uid on a executable is a security risk, since every user will be able to execute it with the rights of the super user....
Thank you poison,
The scriptfile will now load my ethernet driver by clicking a link on the desktop or from the command line as a regular user, but dhclient eth0 still does not run unless I am logged in as su. I have copied the error returned below:
can't create /var/lib/dhcp/dhclient.leases: Permission denied
SIOCSIFADDR: Permission denied
SIOCSIFFLAGS: Permission denied
SIOCSIFFLAGS: Permission denied
Open a socket for LPF: Operation not permitted
if it contains command which can onlly be issued by root, you have to set the uid or execute it as root...
to set the uid
chmod u+s <scriptname>
when you log out the root command now, you should be able to use it as plain user...
Having ascript with SUID set doesn't work. Only binary executables can be set SUID. This is done deliberately because of the security risks. If you want to run ascript as root while being a regular user, you should use su -c <scriptname> but you'll have to provide the root password every time when you run it. Use sudo <scriptname> if you want to type type root password every time. For sudo you'll have to make an entry for ypur scriptin /etc/sudoers. See "man sudo" and /etc/sudoers for more info.
I took this from a tutorial section "limit the user to only specific commands"
It looked straight forward but isnt working as I'm trying to use it.
I get the error mesg. "teabear is not allowed to run makitgo on localhost as root"
Thank you for any help.
<edit>
To add to what I have tried, A couple of variations of "teabear ALL=........" and when I searched these forums for "sudo" I only got 9 pages of results so I have looked through most of those threads but not yet found specific info that I'm after.
<edit>
I hit on this as the entry in my sudoers file under "user privlidge specification" it still allows me to run the scriptfile as a regular user from the command line and the commandsin the file work as I want them to:
teabear localhost=/home/teabear/makitgo
This looks like it will only give access to the one command, is that correct?
If so, my problem now is running it (makitgo) from a link on my desktop.
I will start wacking away at that, but if any one has info to help me out it is still greatly appreciated!
<edit>
Ok, functional now, I tacked , /sbin/dhclient onto the line teabear localhost=/home/teabear/makitgo,
Still if anyone sees security problem or poor security practice with this please let me know.
Thank you very much.
Last edited by toastermaker; 01-05-2004 at 12:53 AM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.