"Learning God-RHEL7" 1-28-MARIADB database automatic backup and use of expect

Source: Internet
Author: User

What this section says:

Case 1: Automatic backup MARIADB script

Actual combat:

1. Automatic backup mariadb Script

need to be prepared: Log on to the server

installation Mariadb-server

Open mariadb-server

[Email protected] ~]# yum-y install mariadb mariadb-server

Package MARIADB #mariadb数据库Linux下的客户端

Package MARIADB-SERVER#MARIADB Database

[[Email protected] ~] #systemctl start mariadb

[[email protected] ~]# rpm-qf ' which MySQL '

Mariadb-5.5.41-2.el7_0.x86_64

[[email protected] ~]# MySQL

Welcome to the Mariadbmonitor. Commands End With; or \g.

Your MariaDB ConnectionID is 2

Server VERSION:5.5.41-MARIADB MariaDB Server

Copyright (c), 2014,oracle, MariaDB Corporation Ab and others.

Type ' help; ' or ' \h ' forhelp. Type ' \c ' to clear the current input statement.

MariaDB [(none)]> showdatabases;

+--------------------+

| Database |

+--------------------+

| Information_schema |

| MySQL |

| Performance_schema |

| Test |

+--------------------+

4 rows in Set (0.01 sec)

MariaDB [(None)]>exit;

Bye

Backup script:

Description

Find. -type f-name *.sql |xargs RM-RF

Xargs construct the parameter list and run the command

Sh-x Debug Scripts

Automatically unzip the ZIP packet script

The following script for the Automatic decompression zip package script, for reference only, can be modified according to the actual situation, can be extrapolate, applied to other applications.

awk-f. ' {print $ #awk} ' Column Operations

-F. with. As a delimiter

Print Input

$ represents every 2 columns

Actual combat: Expect enables no interactive login

expect is created on the basis of TCL, it also provides some of the TCL does not have the command, it can be used to do some Linux under the interaction of some command operation

Installing expect

[Email protected] ~]# Yum-yinstall expect

can also be installed through the source package method

SOURCE Download Link

Http://jaist.dl.sourceforge.net/project/tcl/Tcl/8.6.4/tcl8.6.4-src.tar.gz

Http://sourceforge.net/projects/expect/files/Expect/5.45/expect5.45.tar.gz/download

Ways to create scripts using expect

1 ) defines the shell that the script executes

#!/usr/bin/expect

This defines the link path (or real path) of the expect executable, which is similar to shell features like bash

2 ) Set timeout

Set the time-out, in seconds, if set to timeout-1 meaning never timeout

3 ) Spawn

Spawn internal commands that can be executed after entering the expect environment and cannot be executed directly in the default shell environment

Key Features: Transitive interaction directives

4 ) Expect

The expect here is also expect's internal command.

Main function: Determine whether the output contains a string, not immediately return, or wait for a period of time to return, wait time is set by timeout

5 ) Send

Performs an interactive action to enter an interaction to perform an action into an interactive instruction

Add "R" at the end of the command string, and check if there is an abnormal wait state

6 ) Interact

Keep the interaction state after execution and give control to the console

If you do not add this item, the interactive completion will automatically exit

7 ) Exp_continue

Continue with the next interactive operation

8 ) $argv

expect The script can accept arguments passed from bash, can be obtained using [lindex $argv n], n starting from 0, representing the first, second, third ... Parameters

Combat: No interactive SSH remote login via expect

[Email protected] ~]# Vimssh.exp

#!/usr/bin/expect

Set IPAddress "192.168.1.69"

Set passwd "123456"

Set Timeout 30

Spawn ssh [email protected] $ipaddress

Expect {

"Yes/no" {send "yes\r"; Exp_continue}

"Password:" {send "$passwd \ r"}

}

Interact

Execution Result:

[Email protected] ~]#./ssh.exp

Spawn ssh [email protected]

[email protected] ' s password:

2 ssh telnet by calling bash's location parameter

[Email protected] ~]# Vimssh2.exp

#!/usr/bin/expect

Set IPAddress [LINDEX$ARGV 0]

Set passwd [lindex $argv 1]

Set user [lindex $argv 2]

Set Timeout 30

Spawn [email protected] $ipaddress

Expect {

"Yes/no" {send "yes\r"; Exp_continue}

"Password:" {send "$passwd \ r"}

}

Interact

Execution results

[Email protected] ~]#./ssh2.exp 192.168.1.69 123456 Root

Spawn [email protected]

[Email protected] ' Spassword:

Last login:wed Dec 3021:47:25 from 192.168.1.68

Please leave a message if you have any questions during the learning process. For more information, please add:
Learning God It-linux Lecturer-RM Teacher qq:2805537762
Learn God it-teacher qq:3341251313
Learn God it-Xu Bin qq:372469347
Learn God it education RHEL7 Exchange Group: 468845589


This article is from the "Learn God IT Education-instructor Mk" blog, please be sure to keep this source http://xuegodlinux.blog.51cto.com/10844319/1730153

"Learning God-RHEL7" 1-28-MARIADB database automatic backup and use of expect

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.