撇嘴看天空

导航

linux 批量scp 脚本

scp.sh

#!/bin/sh
ip_list=/home/tools/scp/iplist
src_file=/home/probecheck.sh
dest_file=/home/
username=root
password=123456
cat $ip_list | while read line
do
   host_ip=`echo $line | awk '{print $1}'`
   echo "$host_ip"
   ./scp.exp $host_ip $username $password $src_file $dest_file
done

 

scp.exp

#!/usr/bin/expect
set timeout 10
set host [lindex $argv 0]
set username [lindex $argv 1]
set password [lindex $argv 2]
set src_file [lindex $argv 3]
set dest_file [lindex $argv 4]
spawn scp $src_file $username@$host:$dest_file
 expect {
 "(yes/no)?"
  {
   send "yes\n"
   expect "*assword:" {send "$password\n"}
  }
   "*assword:"
  {
    send "$password\n"
  }
  }
  expect "100%"
  expect eof

posted on 2019-06-13 19:20  撇嘴看天空  阅读(420)  评论(0编辑  收藏  举报