ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
I am writing a bash script. I run it as root, and inside the script I create a user x and
"su - x". I then want to continue running the script as the user x. This seemed impossible as the script stopped until I exited back to root, and then it continued. I've figured out a way around this by creating a .bash_profile for x before I "su - x" that tells it to run automatically a script that I create beforehand. If I haven't lost you yet, then you're nuts. In essence, I would like to do one of the following:
1) Run a script as user and then have it automatically exit back to root. Something like "Run scipt as x", and then when it's done, I'm root again.
OR (by solving the following problem, I have figured a way around the first one)
2) If I'm currently user x, is there a command I can type that will guarantee exiting back out to root? I've tried to put "exit" at the end of my script, but it doesn't seem to run it. Similarly with logout. I currently have a script running as root, so if I put "su - root" at the end of the script I'm running as x, will it continue the original root script, or will this new "root environment" be different from the original one?
If you can help me, that would be great. If you're wondering what the heck I'm trying to do, I'll tell you. I'm attempting to create an automatic LFS (Linux from Scratch) install script for Knoppix. I guess another, more simple question to ask is this : "Is it necessary to su - lfs to install chapter 4 in knoppix?
If you don't know what LFS is, I'd still appreciate an answer to my problems above. Thank-you in advance.
What about setuid? By setting this bit (with chmod) you can make a program run as a specified user. I think, anyway But it seems a bit strange to change a file's permissions when it is executed... Maybe you could split your script in two parts?
Oh, believe me, the script is already into 4 parts. I'm not exactly sure what you mean by setuid and chmod. I mean, I know what the commands are, but they don't really solve my problem. Thanks anyway though. I'm going to try "su - x -c "stuff". That seems so simple, I can't believe I didn't think to look at the su man page. Thanks everybody! I'll let you know if it works.