LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   linux SU command closing script prematurely. help please? (https://www.linuxquestions.org/questions/programming-9/linux-su-command-closing-script-prematurely-help-please-417590/)

Frelov 02-20-2006 10:49 AM

linux SU command closing script prematurely. help please?
 
I'm totally new to scripting. Please help me. I've tried reading http://www.freeos.com/guides/lsst/ but I haven't found anything to specifically address commandline interface with standard commands that require password entering.

Distribution:Fedora Core 4 linux

Issue:
Since the gnome network manager/configuration wizard doesn't recognize my ndiswrapper installed wireless I tried writing a script to activate the wireless card.

IF i manually open a terminal and switch to root I can successfully execute a single script to activate. I tried adding the su to the script so I could assign it to a pointer/shortcut on the launch panel

when I run the script with the su command in it requests the root password then just exits to the command line. This is what I've written:
su
sleep 2
echo configuring wireless card
/sbin/iwconfig wlan0 essid <ESSID>
/sbin/iwconfig wlan0 mode Managed
/sbin/iwconfig wlan0 key restricted <KEY>
/sbin/dhclient wlan0
sleep 5
/sbin/ifconfig wlan0 up
sleep 2
echo wireless card configured
sleep 2
exit
exit

This didn't work so I tried a script to execute other scripts with the first switching to root. always the su terminates all the scripts.

I've tried googling several different keywords in an effort to find something related to this but have had no luck.

I've asked in the wireless networking how to get the network manager to recognize the ndiswrapper installed system but have gotten zero responses.

The reason I need this to be simple is because my computer is used by others who aren't so computer literate (even less than me) and I'd like them to be able to just click on an icon, enter the root password and everything happen automatically,

I'd actually PREFER not having to share the root password but since I can't find an answer to the wireless network gui question this is my next approach.

Would someone please help me?
Thanks so much.

jlliagre 02-20-2006 11:00 AM

remove the "su" command from your script, it launches a different shell and is unrelated to the remaining of the script.
Instead, have a look at the "sudo" command.

Frelov 02-20-2006 12:06 PM

Thanks,

After reading up on sudo and sudoers I added

%users ALL=(ALL) ALL

to the sudoers file

and prefaced each command with sudo. I tried a single command since the man file states it gives 5 minutes of privileges unless manually changed in sudoers but I had to put it in front of each one.

It works now but does not require a password, not even the user password. I thought that the above line in sudoers would not allow bypassing the password. Does this open my system to vulnerabilities? Thanks.

jlliagre 02-20-2006 01:01 PM

Quote:

Originally Posted by Frelov
It works now but does not require a password, not even the user password.

Allowed users have already given their password to log in.

Quote:

I thought that the above line in sudoers would not allow bypassing the password. Does this open my system to vulnerabilities?
Less than having root's password stored on file !

Frelov 02-20-2006 01:14 PM

Ok, thanks. I appreciate the guidance and help. This certainly makes it much easier than having to teach people how to go to the command line and switch to root and run a script.

Thanks a ton.


All times are GMT -5. The time now is 11:59 AM.