ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Trying to automate LFS I came to a problem. There are a few places were you have to switch user and when it finds that line the script stops with the new user at the prompt.
Code:
su - lfs
lfs@DebianKey:~$
That is the line it reads and were the script stops.
Anything I can do to keep going (without manual input)?
There are other places where the user changes as well.
Of course it is not the scripts fault. What I want is for the next commands to keep executing (the next series of lines). How can I do that with the -c option?
Well I'm not sure if this would be the best approach but you could use a heredoc.
Code:
su - lfs<<EOF
<password>
echo ""
...
EOF
For <password> you just enter the lfs password. I'm guessing this would be okay since lfs is just a temporary user for building your system so security isn't really a concern. Then put 'echo ""' to print a newline and the rest of the commands.
I tested this out with:
Code:
su - $USER<<EOF
<password>
echo ""
whoami
EOF
and it worked as expected but there might be other considerations I'm unaware of.
Thanks for your time.
after some more careful studying, it looks like there was an su root at the beginning, an su lfs (for a short time) and back to su root. I bypassed the first one by removing it and switching to root before the start and decided to commend out the lfs user lines and do all of it as root. The documentation says that the user is set up basically to avoid doing mistakes in the host system so I guess it's okay to leave him out. I went further down the script and stopped in a makefile error. So I guess this thread is over, no need to do anything about it, just by pass it. Thanks again.
Seeing your last answer, it's like you laid a trap for this. Good one. Maybe it's gonna be useful for someone coming on this thread.
Thanks for your time.
after some more careful studying, it looks like there was an su root at the beginning, an su lfs (for a short time) and back to su root. I bypassed the first one by removing it and switching to root before the start and decided to commend out the lfs user lines and do all of it as root. The documentation says that the user is set up basically to avoid doing mistakes in the host system so I guess it's okay to leave him out. I went further down the script and stopped in a makefile error. So I guess this thread is over, no need to do anything about it, just by pass it. Thanks again.
Seeing your last answer, it's like you laid a trap for this. Good one. Maybe it's gonna be useful for someone coming on this thread.
Would you mind posting the original script from the book or giving me the page number of its location?
If you are root and use su - lfs you will not be prompted for a password as root can login to all accounts.
As for multiple lines / commands, my suggestion would be to place the lfs protions in there own script and then simply call that script:
Code:
su - lfs -c /path/to/script
This will return to your current script once the lfs one has completed
As a side note, you really should follow the safety recommendations of the LFS manual as it is tried and tested, so I would imagine they have a good reason
If I understood well, you are saying to split the script and issue the command adding the second part to run from it. Good to know, copied that for future reference (as I usually do with useful answers).
I usually follow guidelines, but in this case I do not mind loosing all the stuff I have in the computer which is a test computer.
Edit. This was actually posted on answer #6 but I did not understood it well. Some clarification is needed sometimes.
Last edited by Debian6to11; 03-10-2022 at 10:21 AM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.