Quote:
Originally Posted by hamedhsn
i have a shell script which some of the lines should be running as root and some other not.the problem is that su is not practically work,it means it take root password from me but it does not run the commands in script.
the other problem is that there are some commands which should be run as normal user so how it exits from root mode and run that particular command. i tried exit in script file but it dos not work.
|
Hello there! You sound frustrated.
Of course EXIT won't work with a script -- the command you need for that is ctrl-C, usually.
My question is: Why do you need to exit from ROOT mode in the middle of a script? Once you're in ROOT mode, it seems best to leave it that way until you have finished running the script. After all, if anyone can do a thing, ROOT can certainly do so too. Indeed, if you do terminate a script in ROOT or an individual user mode, the script is done anyway, as far as the computer is concerned -- in fact, you cannot change user while in the middle of a script!
As to SU ... it should leave you in root mode if it is there that you sign in. IOW, while you are in ROOT mode, all commands should be seen as coming from ROOT. It therefore would surprise me greatly if you in fact wrote me back to say that "SU did indeed run the ___ script." In fact, SU's sole purpose in life is to enable you to temporarily login as either another user or as ROOT. As such, it tends to function quite successfully. Have you carefully looked at your system's prompt? If you're logged in as ROOT, it seems to me that it should identify this fact with a "#"; otherwise, I believe that it normally uses a "$".
Good luck!!