سؤال

Im trying to write a bash script that executes several commands as different users to automate an install process.

At one point I have

su gpadmin
gpperfmon_install --enable --password password --port 5432
y  
gpstar
y 

The su gpadmin is run as root, and once it is run the script stops until I exit gpadmin and return as root.

How would one switch to a new user without halting the script?

Sorry for my ignorance, I attempted to google but found nothing that worked. Any help would be greatly appreciated.

هل كانت مفيدة؟

المحلول

You need to use the -c option to su in order for it to run a command and then exit. With the options you have given to su, it will run gpadmin's default shell, which will block until the shell has exited. Judging by the code you already have, it appears that gpperfmon_install is an interactive application, which is another issue. Sometimes you can use a here document, but in other cases you will need to use expect.

su gpadmin -c 'gpperfmon_install --enable --password password --port 5432 << EOF
y
gpstar
y
EOF'
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top