#!/bin/bash #author: QingFeng #qq: 530035210 #blog: http://my.oschina.net/pwd/blog #自动添加秘钥认证用户 #缺省的配置如下 logdir=/data/log/shell #日志路径 log=$logdir/shell.log #日志文件 is_font=1 #终端是否打印日志: 1打印 0不打印 is_log=1 #是否记录日志: 1记录 0不记录 basedir="/data/ehuzhu" yes=$(date -d yesterday +%Y-%m-%d) yesmonth=$(date -d yesterday +%Y-%m) host=x.x.x.x user=admin pass=xxxxxxx datef(){ date "+%Y-%m-%d %H:%M:%S" } print_log(){ if [[ $is_log -eq 1 ]];then [[ -d $logdir ]] || mkdir -p $logdir echo "[ $(datef) ] $1" >> $log fi if [[ $is_font -eq 1 ]];then echo -e "[ $(datef) ] $1" fi } download(){ if [[ $host == "" ]];then print_log "ftp的服务器IP不能为空." exit fi if [[ $user == "" ]];then print_log "ftp的用户名不能为空." exit fi if [[ $pass == "" ]];then print_log "ftp的密码不能为空." exit fi if [[ ! -d $basedir/$yesmonth/$yes ]];then mkdir -p $basedir/$yesmonth/$yes fi print_log "开始下载...$host:$yes目录到=>$basedir/$yesmonth/$yes." ftp -v -n <<! open $host user $user $pass binary cd $yes lcd $basedir/$yesmonth/$yes prompt mget * close bye ! print_log "下载完成...$host:$yes目录到=>$basedir/$yesmonth/$yes." } download #for i in {1..160} #do #yes=$(date -d "$i days ago" +%Y-%m-%d) #yesmonth=$(date -d "$i days ago" +%Y-%m) #print_log "$yes ==> $yesmonth" #download #done
时间: 2024-10-10 14:58:51