ftp自动下载 发表于 2015-05-26 | 分类于 Shell相关 | | 阅读次数 | 字数统计 244 | 阅读时长 1 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778#!/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.xuser=adminpass=xxxxxxx datef(){date "+%Y-%m-%d %H:%M:%S"} print_log(){if [[ $is_log -eq 1 ]];then[[ -d $logdir ]] || mkdir -p $logdirecho "[ $(datef) ] $1" >> $logfiif [[ $is_font -eq 1 ]];thenecho -e "[ $(datef) ] $1"fi}download(){if [[ $host == "" ]];thenprint_log "ftp的服务器IP不能为空."exitfi if [[ $user == "" ]];thenprint_log "ftp的用户名不能为空."exitfiif [[ $pass == "" ]];thenprint_log "ftp的密码不能为空."exitfiif [[ ! -d $basedir/$yesmonth/$yes ]];thenmkdir -p $basedir/$yesmonth/$yesfiprint_log "开始下载...$host:$yes目录到=>$basedir/$yesmonth/$yes."ftp -v -n <<!open $hostuser $user $passbinarycd $yeslcd $basedir/$yesmonth/$yespromptmget *closebye!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 坚持原创技术分享,您的支持将鼓励我继续创作! 赏 微信打赏