Introduction to the distribution system, remote login with expect script, remote execution of commands with expect script, parameter transfer by expect script

Introduction to the distribution system

Scenario: As the business grows, the programming language used by the website or APP server is PHP, the lamp or lnmp environment needs to be configured, and the code needs to be uploaded to the server. However, the business functions are constantly increasing and the code needs to be changed. If there are dozens or hundreds of machines, a distribution system is needed to release the updated code to the new machine.

Core shell script: expect, which can transfer files and execute commands remotely

Ideas: First, prepare a template machine, the code on the machine is the latest code (ready to go online), and then you need to know the IP address of the online machine, the corresponding user's password, use the expect script, and push these codes to the machine with the help of rsync , you can also execute some commands through expect.

expect script remote login

First install expect

Automatic remote login

Add execute permission

Execute the expect script and log in successfully

expect script to execute commands remotely

expect "]*" , when it matches "]", execute the command

telnet and execute command then exit

View execution results

expect script to pass parameters

execute script

Execute multiple commands, enclosed in double quotes

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326939525&siteId=291194637