In general, you may need to switch the root user to another user for execution during the automation process, such as: Oralce
However, the execution of the command will return to the root user, continue to execute other commands under the root user.
You need to know the parameters of the SU command-C or-s
Like what:
# su-oracle-c "PWD"
/home/oracle
Or
Su-oracle-s/bin/sh test.sh
The relevant commands in the test.sh executed at this point are to be bin/sh, in other words, bin/sh supported commands can be executed.
Of course we can redirect the results to other files, and then parse the file again after execution to find the results we need to automate the execution.
Of course we can edit a shell script to perform user Switching.
such as: VI test.sh after entering the following content
#!/bin/bash
Su-test <<eof
Pwd
Exit
Eof
Press [ESC] key, enter: Wq, return to save exit.
After chmod 777 test.sh
Execution: Sh test.sh or. test.sh or./test.sh
ok! problem solved.
How to switch users to execute the appropriate command or shell script in a shell script