• 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
    "
    
  • 相关阅读:
    Nginx的访问控制
    远程登录
    Linux的网络命令
    laravel-collect
    laravel-model
    laravel-Macroable
    laravel-容器
    机器学习-Logisitic回归
    机器学习-多变量线性回归
    算法笔记-分支界限法
  • 原文地址:https://www.cnblogs.com/aworkstory/p/12965709.html
Copyright © 2020-2023  润新知