Quote:
Originally Posted by
robertkwild
Hi Robin yes im confused, what do you mean sudo_user
do you mean for every command i have in my script put sudo infront of it
then i thought instead of putting sudo infront of every command just make the user type su and job done ie from there it will run all the commands as root
I thought I explained this in post #4 in this thread when I said:
Quote:
Nothing in your script after invoking su will be run with root privileges. The su utility, if given a proper password, will start a shell and nothing in the rest of your script will be run until that shell exits.
Once a user types the root password in response to invoking the command
su (without operands), they can then type any commands into the shell that
su starts for them and it will run those commands with all of the privileges of someone who logged in as root. When they exit that super-user shell, your script will then continue running with the same privileges as the user who invoked that utility had when they invoked your script. No commands in your script after the shell started by
su exits will run with root privileges unless it was root who invoked your script to being with.
The here-document trick I also showed you in that post can be used to feed commands into that super-user shell. The text in that here-document is just read and executed by the shell that
su starts; it is not that
su is running commands in your script.
The logical easy way to do this (if a user who is going to run your script knows the root password and wants to run your script with root privileges) is for them to run
su and then while in the shell that
su starts have them run your script and do whatever else they need to do as root before exiting that super-user shell.