Issue: After executing the "su– username" in the shell script, the script terminates execution and switches to the interactive interface behavior of the specified user name in su: I execute a script in root, but some of these commands or scripts must be executed by the Oracle user. ,
[Email protected]vi /data/itf/app/oracle/sync/test. SH #!/bin/-xsu -/nolog <<eofconn hxy/ Select * from dba_tables;exiteof
After executing sh/data/itf/app/oracle/sync/test.sh under the root user, stopping the interface of the Oracle user is not performed down, it is necessary to manually enter exit to continue, but it is not good to include the exit in the script
Analysis: A, su– directly after the environment and wait for the user's interactive access, do not continue to execute the script command B, the SU after the bash is a child shell, the script to write exit no use, these will wait until the end of the SU process to execute. Solution: su– User-C command or sudo-u user Command Reference example: resources: Switch users in the Shell and the script changes to the following way
#!/bin/
su-oracle-c sqlplus/nolog << EOFconn hxy/Select *
Scripts run smoothly
or change to:
#!/bin/
Su-oracle <<! /nolog <<eofconn hxy/Select *
!
can also be executed smoothly
Shell cannot execute post-su script