Switching user stops script
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 Anything I can do to keep going (without manual input)? There are other places where the user changes as well. |
Well you can't fault the script as it did exactly as you instructed, ie it logged in as lfs.
As you have not shown what you want the lfs user to do at this point, my guess would be you need to look at the '-c' option for su |
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?
|
Trying this, I get
Code:
su -c lfs |
Same thing happens if I use "su -c root" at the top of the script:
bash: line 1: root: command not found Where the next line is a mkdir line. |
Quote:
Code:
su lfs -c <command> |
Of course you could also do:
Code:
sudo lfs -c "<command; command; command; ...>" |
But I get an error already. Besides, it is another 150 lines for a start. I shouldn't just stuck them all in one line.
|
And I will be switching user in other parts of the script (and the next 2 parts). It's gonna be 3 scripts which if successful I will be joining them.
|
Well I'm not sure if this would be the best approach but you could use a heredoc.
Code:
su - lfs<<EOF I tested this out with: Code:
su - $USER<<EOF |
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. |
Quote:
|
|
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 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. |
All times are GMT -5. The time now is 11:19 AM. |