简体   繁体   English

更新bash脚本,文件检查,如何?

[英]Update bash script, file check, how?

#!/bin/sh

LOCAL=/var/local

TMP=/var/tmp

URL=http://um10.eset.com/eset_upd

USER=""
PASSWD=""

WGET="wget --user=$USER --password=$PASSWD -t 15 -T 15 -N -nH -nd -q"

UPDATEFILE="update.ver"

cd $LOCAL

CMD="$WGET $URL/$UPDATEFILE"
eval "$CMD" || exit 1;
if [ -n "`file $UPDATEFILE|grep -i rar`" ]; then
(
  cd $TMP
    rm -f $TMP/$UPDATEFILE
      unrar x $LOCAL/$UPDATEFILE ./
      )
      UPDATEFILE=$TMP/$UPDATEFILE
      URL=`echo $URL|sed -e s:/eset_upd::`
      fi
      TMPFILE=$TMP/nod32tmpfile
      grep file=/ $UPDATEFILE|tr -d \\r > $TMPFILE
      FILELIST=`cut -c 6- $TMPFILE`
      rm -f $TMPFILE
      echo "Downloading updates..."
      for FILE in $FILELIST; do
        CMD="$WGET \"$URL$FILE\""
          eval "$CMD"
          done
          cp $UPDATEFILE $LOCAL/update.ver
          perl -i -pe 's/\/download\/\S+\/(\S+\.nup)/\1/g' $LOCAL/update.ver
          echo "Done."

So I have this code to download definitions for my antivirus. 因此,我有这段代码可以下载防病毒软件的定义。 The only problem is that, it downloads all files everytime i run script. 唯一的问题是,每次我运行脚本时,它都会下载所有文件。 Is it possible to implement some sort file checking ?, let's say for example, 可以实现某种排序文件检查吗?例如,

"if that file is present and have same filesize skip it" “如果该文件存在并且文件大小相同,请跳过它”

Bash Linux Bash Linux

The -nc argument to wget will not re-fetch files that already exist. wget的-nc参数不会重新获取已经存在的文件。 It is, however, not compatible with the -N switch. 但是,它与-N开关不兼容。 So you'll have to change your WGET line to: 因此,您必须将WGET行更改为:

WGET="wget --user=$USER --password=$PASSWD -t 15 -T 15 -nH -nd -q -nc"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM