开发者

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


The -nc argument to wget will not re-fetch files that already exist. It is, however, not compatible with the -N switch. So you'll have to change your WGET line to:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜