Strive_tan shell programming actual combat 2-distribution system

1. Expect applications

1) Transfer files

2) Execute commands remotely, no interaction, no need to enter a password

3) The core of the online shell script (tool) is expect, which is the distribution system.

2. Expect installation

yum install -y expect

3. Expect language Example 1: Automatically log in to a server remotely

#! /usr/bin/expect

set host “192.168.133.132”

set passwd “123456”

spawn ssh [emailprotected]$host

expect {

“yes /no” {send “yes
“; exp_continue}

“password:” {send “$passwd
” }

}

interact< /p>

4. Expect language example 2: After automatically logging in to a server remotely, and executing the command

#!/usr/bin/expect

set user “root”

set passwd “123456”

spawn ssh [email protected]

expect {

“yes/no” {send “yes
“; exp_continue}

“password: “{send “$passwd
” }

}

expect “]*”

send “touch /tmp/12.txt
“< /p>

expect “]*”

send “echo 1212> /tmp/12.txt

expect “]*”

send ” exit

5. Passing parameters of expect script

#!/usr/bin/expect

set user [lindex $argv 0]

set host [lindex $argv 1]

set passwd “123456”

set cm [lindex $ argv 2]

spawn ssh [email protected]$host

expect {

“yes/no” {send “yes
“}

“password:” {send “$passwd
” }

}

expect “]*”

send “$cm

expect “]*”

send “exit

$ argv0 Indicates the parameter to be passed to the variable user; $argv1, $argv2 are the same.

6. Sync file of expect script

Share picture

7. Build file distribution system for expect script

Share pictures

8.

< p>#!/usr/bin/expect

set host [lindex $argv 0]

set passwd “123456”

set cm [lindex $argv 1]

spawn ssh [email protected]$host

expect {

“yes/no” {send “yes
“}

“password:” {send “$passwd
” }

}

expect “]*”

send “$cm

expect “]*”

send “exit

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 5543 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.