wget 整站下载

536阅读 0评论2009-08-05 ryan3216
分类:LINUX

# !/bin/bash
# getmirror -- to wget a website in your device as a mirror, and manage the mirrorlist
# using:
#    getmirror [-d ]     -- save the website in the directory your specify
#                         or using the default
# getmirror ud                 -- update the mirror in the directory
# getmirror dir          -- specify your mirror directory as a default
#    getmirror add             -- add a new website in your mirror list to manage
#                         the default mirror
GMDIR=$HOME/.wget
PREFDIR=$GMDIR/prefdir
MIRLIST=$GMDIR/wgetlist
test ! -d $GMDIR && mkdir $GMDIR
test ! -e $PREFDIR && echo $HOME/webmirror > $PREFDIR
# give the website to the directory you prefer, default is $HOME/webmirror
case $1 in
    dir)
    if [ -z $2 ];then
        echo "Current mirror directory is "`cat $PREFDIR`
        echo -e "Use \"getmirror dir [directory]\" to change it."
        exit 0
    fi
    mkdir $2
    cd $2 && echo `pwd` > $PREFDIR
    ;;
    add)    
    if [ -z $2 ]; then
        echo "No website specified."
        exit 0
    fi
    echo $2 >> $MIRLIST
    ;;
    ud)
    test ! -e $MIRLIST && echo "there’s not mirrorlist. you should using getmirror add  first." && exit 0
    cd `cat $PREFDIR` && wget -m -t99 -l1 `cat $MIRLIST`
    ;;
    -d)
    if [ $# != 3 ]; then
        echo "Usage: getmirror [-d directory] website"
        exit 0
    fi
    CURDIR=$2
    test ! -d $CURDIR && mkdir $CURDIR
    test ! -w $CURDIR && echo "Error: current directory isn’t writeable." && exit 1
    cd $CURDIR
    wget -m -t99 -l1 $3
    ;;
    *)
    if [ $# = 0 ];then
        echo -e "Usage:
    getmirror [ option  | command ]
Option:
    [-d ]     -- save the website in the directory you specify or
                      using the default
Command:
    dir             -- specify your mirror directory as a default
    add             -- add a new website in your mirror
    ud                -- update your mirror"
        exit 0
    fi
    CURDIR=$PREFDIR
    test ! -d $CURDIR && mkdir $CURDIR
    test ! -w $CURDIR && echo "Error: current directory isn’t writeable." && exit 1
    cd $CURDIR
    wget -m -t99 -l1 $1
    ;;
esac
 
reference:
上一篇:setsockopt(设置socket状态)
下一篇:tcpdump抓包分析详解