问题
I currently have a script to help me automate an install. During this install I have to switch from root to another user, gpadmin, and run the final leg of the install. At this point I call:
su - gpadmin -c 'echo source /usr/local/greenplum-perfmon-web-4.1.2.0-build-2/gpperfmon_path.sh > .bashrc2;
source ~/.bashrc2;
gpperfmon --setup'
This works but I have to manually go through the EULA and other parameters. I had used a here document to go through and finish everything but for some reason this would prevent the creation of a security certificate and break the install. To circumvent this I wanted to attempted to use expects after the gpperfmon --setup command. Will these expects be called correctly even though they are being passed to a different user using the ticks?
回答1:
After tinkering around I found that the expect does work. I was mistaken in what I though expect was exactly.
spawn "/gp/install/gppermon.bin"
expect "EULA:"
send \003
That works to circumvent the EULA, and the entire SU process is not required.
来源:https://stackoverflow.com/questions/9022445/bash-su-expect-combo