Operating Systems > Linux and UNIX

Script Writing Quetsion in Linux

(1/3) > >>

LorKorub:
Suppose that I wanted to write a script that allows me (logged in as a normal user) to generate a Root Xterm and launch a program all in one shot.  For example, to use my DSL client, I have to log in as root, and then launch my PPPoE client.  As of right now, I have two scripts performing this routine and I would like to cut it down into one.

Any suggestions? Can this be done? Or does this defeat the purpose of a Root logon?

Also, if we are capable of performing the above routine, how do you program "hot keys" like you do in UNIX?

badkarma:
yes it can be done .... I'm not sure as to how though (if you just start "su" the rest of your script won't be executed (not untill you leave the root shell anyway) however I know that in SuSE there is a script "sux" which runs su and sets the DISPLAY variable to the correct setting)

if nobody answered your question in a few days I'll take some time to figure it out (or you can and tell me how ;) cause it's quite usefull for me too.....

voidmain:
There are many ways to do what you are asking in general.  The best way to launch selected programs "as root" by any normal user without requiring a password is "sudo".  See the man pages and documentation, there is plenty of it out there.

For PPP/PPPoE you can either use the above method, or you can try something like this:
http://support.aznet.net/setup/linux-ppp.shtml
And there are other similar methods.

You may also want to check out "diald" which will automatically dial your provider when a network connection outside of your local network is attempted.  I used to use this many moons ago before I got cable.  I had several machines on my home network and if any one of them tried to connect to the internet my Linux internet gateway would automatically dial my provider and become a masquerade server for any of my clients. It would hang up after 15 minutes of inactivity (configurable).

Again, the possibilities are endless and if you could give a more specific example of your goal I could probably give you a more specific example.  Also if you really want to launch an xterm and have it automatically execute a script, check out the "-e" parameter of "xterm".

LorKorub:
Thanks for the help so far.

Basically, what I have going is a script called "start-pppoe" that I execute as root from /usr/local/bin. All of the parameters and stuff for the DSL hook-up are already in that file.  I edited it according to the help file that was on SBC's website (I actually couldn't believe they supported Linux.) I can execute this as a normal user, but I have to launch an xterm as root in order to gain access to the "start-pppoe."  So, what I wrote so far are two scripts: one called "root" that I execute in an xterm which prompts me for a login. Then one called "dsl" that I launch once I am in a root xterm that changes directory to usr/local/bin and executes "start-pppoe."  What I want to do is simply combine the "root" and "dsl" named scripts into one script so I can do everything in one shot.  Is there a way to impliment or hardcode the root password into a script so I can just execute it, login, and launch my "start-pppoe" in one nice shot? I tried a script that I wrote to accomplish this, but it got me as far as the password login for root, and then it stopped.  It wouldn't continue on and launch "start-pppoe."  All it did ws what Bad Karma described.  Once I closed the xterm window, it would run for some reason.

If you need more info, I can provide it, but I think that pretty much sums it up.  Thanks for the help.

[ June 19, 2002: Message edited by: LorKorub ]

voidmain:
Well, I'm not sure why you have to open an xterm but again, there are a couple of ways to run the start-ppoe as root, one is to use the sudo command which will allow you to execute it as root without prompting for a password, or you could try changing the ownership of the scripts to "root" and setting the sticky bit on the scripts by "chmod u+s scriptname", or you could put this in a script to launch any program/script as root from another script but requiring you to enter root's password:

su - -c "/usr/bin/scriptname"

Maybe if you post the contents of the two scripts in question I would have a better idea of what you are trying to do and could then help you out (or you could send it in a private message if you wish).

Navigation

[0] Message Index

[#] Next page

Go to full version