免密碼複製遠程linux服務器文件

#!/bin/bash
#
#****
#Author: zhang
#QQ: 531908902
#Date: 2019-01-15
#FileName: expect_scp.sh
#URL:
#Description: The test script
#Copyright (C): 2019 All rights reserved
#****
cat name.txt |while read ip user passwd;do
expect <<EOF
spawn scp $user@$ip:/date/* /date/dong
expect "yes" {send "yes\n" }
expect "est" {send "$user\n" }
expect "password" {send "$passwd\n" }
expect eof
EOF
done

其中 name.txt 文件和該腳本都在同一個文件夾
name.txt 格式
172.20.120.39 root centos7
cat的行賦值給while循環的變量
read賦值是一行一行的讀取的 read 後面的變量以空格 分別獲得 name.txt第一行的值,name.txt 格式也是空格隔開
從而賦值以後 執行後面的命令

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章