Author Topic: Script Writing Quetsion in Linux  (Read 829 times)

LorKorub

  • Member
  • **
  • Posts: 175
  • Kudos: 0
Script Writing Quetsion in Linux
« on: 18 June 2002, 16:30 »
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?
"American English -- the noble language of your superiors"

badkarma

  • VIP
  • Member
  • ***
  • Posts: 497
  • Kudos: 0
Script Writing Quetsion in Linux
« Reply #1 on: 18 June 2002, 17:17 »
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.....
If you can't learn to do something well, learn to enjoy doing it poorly.

voidmain

  • VIP
  • Member
  • ***
  • Posts: 5,605
  • Kudos: 184
    • http://voidmain.is-a-geek.net/
Script Writing Quetsion in Linux
« Reply #2 on: 18 June 2002, 21:32 »
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".
Someone please remove this account. Thanks...

LorKorub

  • Member
  • **
  • Posts: 175
  • Kudos: 0
Script Writing Quetsion in Linux
« Reply #3 on: 19 June 2002, 13:27 »
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 ]

"American English -- the noble language of your superiors"

voidmain

  • VIP
  • Member
  • ***
  • Posts: 5,605
  • Kudos: 184
    • http://voidmain.is-a-geek.net/
Script Writing Quetsion in Linux
« Reply #4 on: 19 June 2002, 14:20 »
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).
Someone please remove this account. Thanks...

LorKorub

  • Member
  • **
  • Posts: 175
  • Kudos: 0
Script Writing Quetsion in Linux
« Reply #5 on: 19 June 2002, 15:00 »
VoidMain...

You are the man!  That su - -c "/directory/directory/script" line worked.  I get prompted for the root password, but that is cool. can you somehow integrate the root password into that? Or do you *have* to type it in?

I will PM you some of the details of the scripts in question tomorrow, just in case everyone wasnts to elaborate and expand on this concept further (it is good info for newbies.)

Thanks for the help.
"American English -- the noble language of your superiors"

badkarma

  • VIP
  • Member
  • ***
  • Posts: 497
  • Kudos: 0
Script Writing Quetsion in Linux
« Reply #6 on: 19 June 2002, 19:20 »
quote:
Originally posted by LorKorub:
VoidMain...

You are the man!



nothing new there ... lol  ;)
If you can't learn to do something well, learn to enjoy doing it poorly.

voidmain

  • VIP
  • Member
  • ***
  • Posts: 5,605
  • Kudos: 184
    • http://voidmain.is-a-geek.net/
Script Writing Quetsion in Linux
« Reply #7 on: 19 June 2002, 21:31 »
quote:
Originally posted by LorKorub:
That su - -c "/directory/directory/script" line worked.  I get prompted for the root password, but that is cool. can you somehow integrate the root password into that? Or do you *have* to type it in?



The "sudo" will do what you want as I mentioned before.  If you have it installed you should be able to do a "man sudo" and you should also have a configuration file called "/etc/sudoers".  If you don't have it installed you should have it on your installation CD, it's a small utility. Like many things in UNIX, it isn't the most intuitive utility but it is very powerful and handy and it is security concious.
Someone please remove this account. Thanks...

dbl221

  • Member
  • **
  • Posts: 253
  • Kudos: 0
Script Writing Quetsion in Linux
« Reply #8 on: 20 June 2002, 07:30 »
Uhm... perhaps I am an idiot for saying this but why not just put a symbolic link in /etc/rc.d/rc3.d to the startup script in /etc/rc.d/init.d.  Then pppoe starts up when you boot.

Just smack me if this is out of line.
dbl221***Comp-Sys walking wounded

voidmain

  • VIP
  • Member
  • ***
  • Posts: 5,605
  • Kudos: 184
    • http://voidmain.is-a-geek.net/
Script Writing Quetsion in Linux
« Reply #9 on: 20 June 2002, 21:03 »
Good question, other than maybe he doesn't want to "always" be connected.  I personally would have added it to the "/etc/sysconfig/network-scripts/ifup-post" script.
Someone please remove this account. Thanks...

LorKorub

  • Member
  • **
  • Posts: 175
  • Kudos: 0
Script Writing Quetsion in Linux
« Reply #10 on: 26 June 2002, 15:50 »
"I reached back like a pimp and I smacked that ho" -- Eazy E

Just kidding.  

Thanks for the help so far.  I am still dabbling with the sudo command, and having some difficulty, but I am really interested in hearing about the symbolic link at start-up.  Perhaps someone can go into detail about how to create a symbolic link, where to place it, and how to execute it.

Thanks again.
"American English -- the noble language of your superiors"

choasforages

  • VIP
  • Member
  • ***
  • Posts: 1,729
  • Kudos: 7
    • http://it died
Script Writing Quetsion in Linux
« Reply #11 on: 26 June 2002, 15:57 »
hmmm, sym link, now thats easy

ok here goes

ln -s whatever/you/wanna/link /wherver/you/want/to/put/it


and the symbolic link acts as though it is a real file/*kinda like shortcuts in windows but better*/

[ June 26, 2002: Message edited by: choasforages ]

x86: a hack on a hack of a hackway
alpha, hewlett packed it A-way
ppc: the fruity way
mips: the graphical way
sparc: the sunny way
4:20.....forget the DMCA for a while!!!