2021-05-12 14:32:11
CentOS 7 下 通過shell + expect 實現 scp 檔案(目錄)傳輸
在CentOS 7 下 通過shell + expect 實現 scp 檔案(目錄)傳輸過程記錄, 寫的不多 一點經驗。
scp介紹:
實現終端之間檔案的傳輸,即可以將本地檔案傳送到遠端相應目錄下,也可以將遠端目錄下的檔案拷貝到當前目錄
SYNOPSIS
scp [-12346BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file] [-l limit] [-o ssh_option] [-P port] [-S program] [[user@]host1:]file1 ... [[user@]host2:]file2
本地到遠端:
scp -r filelist[or file] $user@$host:/filelist2
遠端到本地
scp -r $user@$host:/filelist /filelist2
下面就來實現資料夾拷貝 本地到遠端(程式碼範例)
start_check.sh
#!/bin/sh
#yum -y install expect*
SCP_DIR="/opt/dac/data/attach"
T=0
function CheckDir()
{
if [ "`ls -A $SCP_DIR`" = "" ]; then
T=15
sleep $T
else
T=5;
expect ./expect_scp.exp
rm -rf $SCP_DIR/*
sleep $T
fi
}
while [ 1 ] ; do
CheckDir
done
expect_scp.exp
#!/usr/bin/expect -f
set password tips123
set DIR_SCP /opt/dac/data/attach
#upload remote host
spawn scp -r $DIR_SCP root@192.168.2.81:/root/dir_ssh/
set timeout 3
expect {
"yes/no" {send "yesr";exp_continue}
}
expect "root@192.168.2.81's password:"
set timeout 3
send "$passwordr"
set timeout 300
send "exitr"
expect eof
本文永久更新連結地址:http://www.linuxidc.com/Linux/2017-02/140383.htm
相關文章