Shell Write automatic installation script automatically read license and auto input enter

Source: Internet
Author: User

Recently relatively busy, in the company wrote a Centreon+nagios platform source automatic installation script (because the company can not even outside the network, the company Yum source a lot of things are not all, so can only take the source installation), which wrote to install Centreon time, execution./install-i will need to enter read license, and need to read more content, you need to press the space bar to read, the following use expect to achieve this part, if you have a better method, trouble pointing, learn from each other, because the script has been used, so inconvenient to open, here simply to cite an example, After that, we should write some open-source stuff with Python, and please give us a lot of advice.

1, installation expect

Yum-y Install expect*

2, expect and. Install-i Interactive process, the following script is named

#!/usr/bin/expectset timeout 45                        #有些命令需要执行比较久, set 45 here to avoid expect execution of the command procedure exits the set  rrdspath [lindex  $argv  0]        #传参, the following examples illustrate set  pearpath [lindex  $argv  1]    spawn ./ -i                 #需要交互的命令    expect   "Press enter to continue."     #有出现的字符串send   "\ n"                             # After the above string appears, send the carriage return expect  "Modification follow."         #此为读取license底部出现的行send                                   #发送多个空格send   "   "send "   "send "   "send "   "expect " default to *: "                #直到此处, require input select send  "y\r"                              #自动输入中间还有很多略过 ... expect eof

2.1 Executing a expect parameter instance

The following uses SMBPASSWD batch to build the user to example

Bash script

#!/bin/bash i=1for ((i=1;i<=1000;i++)) do./sambaname user${i} [email Protected]${i} #这里就是传入参数了done

The following script is named./samaname

#!/usr/bin/expect-fset username [lindex $argv 0] #和上面类似set password [lindex $argv 1]spawn smbpasswd-a $usernameexpect "*password:" Send "$password \ n" #注意这里发送的是上面的username变量expect "*password:" Send "$password \ n" Expect EOF

The two are placed under the same directory, and then chmod a+x changes the execution permissions, and the second script goes to the first one.

This article is from the "Essays" blog, please be sure to keep this source

Shell Write automatic installation script automatically read license and auto input enter

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: 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.