zoukankan      html  css  js  c++  java
  • ssh自动下载SFTP文件

    话不多说,开门见山,直接放代码

    cron_down_sftp_fill.sh

    #!/bin/bash
    
    ip="140.140.140.140"
    # 从远处服务器下载文件
    PASS="the_real_pwd"
    basePath="/home/dev/cron_dev/bill/"
    
    function down_file {
        echo "yest1:$yest1, yest2:$yest2, fileName:$fileName"
    
        /usr/bin/expect <<EOD
    spawn sftp username@$ip:/THE_SFTP_PATH/$yest1/$fileName $filePath
    set timeout 300
    #第一次ssh连接会提示yes/no,继续
    expect {
    	"*yes/no" { send "yes
    " }
    	"*password" { send "$PASS
    " }
    }
    expect eof
    EOD
    }
    echo -e "$(date "+%Y-%m-%d %H:%M:%S") down file start"
    
    # 下载近11天的文件
    for((i=11;i>=1;i-=1))
    do
        month=`date -d "$i day ago" +%Y%m`
        yest1=`date -d "$i day ago" +%Y%m%d`
        yest2=`date -d "$i day ago" +%y%m%d`
        fileName="MERCHANT_${yest2}01_2020"
        filePath="${basePath}${month}/"
        if [ ! -d $filePath ]; then
            mkdir -p $filePath
            # sudo mkdir -p -m 755 $filePath
            echo "sudo mkdir -p ${filePath} done"
        fi
        if [ ! -f "$filePath$fileName" ]; then
            down_file
        else
            echo "$yest1 file exists"
        fi
    
    done
    
    echo -e "$(date "+%Y-%m-%d %H:%M:%S") down file end
    "
    
  • 相关阅读:
    CentOS7配置RAID10
    CentOS7配置RAID5笔记
    CentOS7改主机名hostname
    CentOS7设置光盘镜像为本地yum源
    VMware安装Windows Server 2008
    VMware安装CentOS7
    xss漏洞介绍
    pakichu-暴力破解
    搭建xcode9的IOS开发环境
    dvwa之xss
  • 原文地址:https://www.cnblogs.com/aworkstory/p/12965709.html
Copyright © 2011-2022 走看看