Shell cannot execute post-su script

Source: Internet
Author: User
Tags exit in

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.