How to push text information to the interaction process in shell scripts

Source: Internet
Author: User
Tags jboss

A buddy raised a question and found it interesting. He studied it below:
The Development Department of this buddy company has written a jboss script to start the jboss program. You need to enter a command similar to the following:
./Jboss_init.sh start
Then, a password will be entered at the prompt of the script to confirm and then start.
The problem is that he doesn't want to manually enter the password, and hopes that the program can automatically complete the input process (because a group of people engaged in technology are very lazy and lazy people have made technological innovations)

To simulate the above general environment, I found the sqlplus program. When the sqlplus Program specifies a user name and does not specify a password, it will prompt the user to enter the password.
As follows:
[Oracle @ rac1 scripts] $ sqlplus mai
SQL * Plus: Release 11.2.0.1.0 Production ction on Wed Sep 4 16:50:34 2013
Copyright (c) 1982,200 9, Oracle. All rights reserved.
Enter password:


The following script is written:
[Oracle @ rac1 scripts] $ more t. sh
#! /Usr/bin/CT
Set timeout 10
Spawn/u02/db_1/bin/sqlplus mai
Reset CT "password :"
Send "mai \ r"
Interact
Note: Most systems do not have the initct tool installed. You need to install it manually. After installation, the program is under/usr/bin/initct.
The preceding timeout indicates a time, which indicates the time when the script pushes the text.
For spawn, it is to execute the relevant trigger command, which can also be a script
Then, you can find the corresponding field and enter the parameter value after it.
Clearly, send is to send text, followed by \ n, which indicates entering a carriage return
Interact restores the current script to the interactive mode. If there is no such line, the script will automatically exit after the delay.


Run the following command:
[Oracle @ rac1 scripts] $./t. sh
Spawn/u02/db_1/bin/sqlplus mai
SQL * Plus: Release 11.2.0.1.0 Production ction on Wed Sep 4 16:53:05 2013
Copyright (c) 1982,200 9, Oracle. All rights reserved.
Enter password: mai


Connected:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0-64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options


SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0-64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options

The preceding results show that the logon is successful. OK!

Note:
In most script programs, the plaintext password cannot be directly written into the script, which may easily cause password leakage.
The SQL plus tool is used to simulate this process. It is not recommended to use this tool because it is useful.

Shell scripts in Linux

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.