Jump to content

Shell commands as root


Recommended Posts

I'd like to be able to re-start my network automatically in 10OE at KDE startup (there's something wrong with my network card and it won't work otherwise!). I've tried putting the (executable) file "network.sh"

#!/bin/bash

 

su

service network stop

service network start

 

into ~/.kde/Autostart and nothing happens. I also just want it to run without having to enter the root password. Is this possible?

 

TIA!

Edited by Dustpuppy
Link to comment
Share on other sites

I'd like to be able to re-start my network automatically in 10OE at KDE startup (there's something wrong with my network card and it won't work otherwise!). I've tried putting the (executable) file "network.sh"
#!/bin/bash

 

su

service network stop

service network start

 

into ~/.kde/Autostart and nothing happens. I also just want it to run without having to enter the root password. Is this possible?

 

TIA!

 

su -c "command 1 && command 2"

 

see "man su". 'su' executes a new shell and once it finishes it returns to its parent shell, so in your script su runs, and ends returning to its caller, hence 'service network ...' calls are from the parent shell not from 'su'

 

btw, don't do it through su (your script can provide root's password automatically each time, for example using 'expect' see its man page, but is trully unsafe) but through permissions and group ids (man chmod) if you trust your users ;)

 

hth

Edited by aru
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...