Batch scp script-copy files from multiple machines
Source: Internet
Author: User
Batch scp script & mdash; copy files from multiple machines to conveniently retrieve logs from multiple servers, A simple script is written to copy server logs in batches to the machine where the script is executed. The script contains two files: bscp. sh and bscp. exp. Usage: shbscp. sh & lt; username & gt ;... batch scp script-copy files from multiple machines in order to conveniently obtain logs from multiple servers, a simple script is written specifically for copying server logs in batches to the machine where the script is executed. The script contains two files: bscp. sh and bscp. exp. Usage: sh bscp. sh Username: your ssh password to the target machine. Host1, host2: ip address or machine name of the target machine, separated by commas. Log_file: the absolute path of the logs to be downloaded in batches. After running, the program prompts you to enter the password of the target machine (here the ssh username and password of multiple machines are the same) bscp. sh main program: [plain] #! /Bin/bash if [$ #! = 3]; then echo "usage: "Exit 1 fi stty-echo # hide password Output read-p" Please enter target hosts 'passwd of $1: "passwd stty echo dirpath = 'dirname $ 0' # echo $ dirpath/bscp. exp $1 $2 $3 $ passwd expect script: [plain] #! /Usr/bin/login CT-f set user [lindex $ argv 0] set hosts [lindex $ argv 1] set logfile [lindex $ argv 2] set passwd [lindex $ argv 3] set timeout 10 set hostlist [split $ hosts ", "] # Split the host string into a list set slashIdx [expr [string last/$ logfile] + 1] set filename [string range $ logfile $ slashIdx end] # get the log file name foreach h $ hostlist {set hostfile $ filename spawn scp $ user @ $ h: $ logfile. /$ filename. $ h CT "* En Ter passphrase for key * "{# Here you can change it to other possible display texts, such as password. or add multiple interactive links to send "$ passwd \ r" send "\ r"} expect CT "* % *" {set timeout-1; puts "\ rtrasmitting... "} completed Ct eof {# puts" \ rtransmit successfully! "Set timeout 10} one chestnut: execute the following command to obtain the logs of three machines :. /bscp. sh ultrani host1, host2, host3/home/admin/xxx/logs/access. the log result is to download the logs of the three machines to the directory where the script is executed. the log suffix ends with the machine name: access. log. host1access. log. host2access. log. host3
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