首页 / 操作系统 / Linux / CentOS 7 下 通过shell + expect 实现 scp 文件(目录)传输
在CentOS 7 下 通过shell + expect 实现 scp 文件(目录)传输过程记录, 写的不多 一点经验。scp介绍:实现终端之间文件的传输,即可以将本地文件发送到远端相应目录下,也可以将远端目录下的文件拷贝到当前目录SYNOPSISscp [-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=0function 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
doneexpect_scp.exp#!/usr/bin/expect -fset 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 "yes
";exp_continue}
}
expect "root@192.168.2.81"s password:"
set timeout 3
send "$password
"
set timeout 300
send "exit
"
expect eof本文永久更新链接地址