Shell, switch user, execute specified, script

Source: Internet
Author: User

In some cases, such as Oracle, you must switch to the specified user to restart Oracle.

Each time the manual operation is more troublesome, you can write a script.

The function of automatically entering password, need to use expect

Install first

Yum Install-y expect

Edit Script

VI aa.sh


#!/usr/bin/expect


Spawn su oracle-c "/opt/1.sh"

Expect "Password:"

Send "123456\r"

Interact

Exit


Note:

1. The first line is #!/usr/bin/expect, not #!/bin/bash, which requires special attention.

2.-C is the command that you need to execute after you specify the switch user. There are multiple commands that can be written in a script. Without the-c option, after switching users, subsequent commands are executed at the current user, not after the user is switched.

3.123456\r indicates that the Oracle password is 123456

4. After the script executes, the input password appears, this time, do not enter the password, wait 12 seconds, will automatically enter the password, and execute the command specified by-C, to ensure that the shell has execute permissions.





This article is from the "Falling Star" blog, make sure to keep this source http://xiao987334176.blog.51cto.com/2202382/1673981

Shell, switch user, execute specified, 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.