Linux Shell 下載網站指定檔案

FrankYou發表於2018-02-05

Shell指令碼,用來從網站下載指定檔名的檔案。先判斷本地這個檔案是否存在,如果存在則忽略,不存在則從遠端伺服器上下載,下載成功後本地的批次號累加1,然後使用新的批次號繼續下載新檔案。

#!/bin/bash
downToday() {
    file1="/download/billdownload/settlements_xx/settlement_detail_report_batch_"
    batchno="`expr $(cat /home/aaa/batchno_xx) + $1`"
    suffix="_`date +\%C\%y\%m\%d`.csv"
    file3="${file1}$batchno${suffix}"
    if [ -f "$file3" ]
    then
        echo "local file:settlement_detail_report_batch_`echo $batchno${suffix}` found" > /home/aaa/settle_xx.txt
    else
        echo "local file:settlement_detail_report_batch_`echo $batchno${suffix}` not found" > /home/aaa/settle_xx.txt
        wget -P /download/billdownload/settlements_xx --http-user=username --http-password=passwd --no-check-certificate -e "https_proxy=proxyurl:proxyport" https://url/reports/download/MerchantAccount/bbbb/settlement_detail_report_batch_`echo $batchno${suffix}`
        if [ -f "$file3" ]
        then
            expr $(cat /home/aaa/batchno_xx) + 1 > /home/aaa/batchno_xx
            downToday 0
        fi
    fi
}

for (( j=0; j<78; j=j+1 )); do
    downToday 0
    downToday 1
    sleep 10m
done

 

編輯crontab檔案以便在指定時間執行排程任務(job)

30 10 * * * /home/aaa/settle_xxx.sh

 

相關文章