Linux Shell 下载网站指定文件

时间:2022-08-09 14:33:54

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