Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1425979
  • 博文数量: 463
  • 博客积分: 10540
  • 博客等级: 上将
  • 技术积分: 5450
  • 用 户 组: 普通用户
  • 注册时间: 2006-11-12 08:30
文章分类

全部博文(463)

文章存档

2014年(2)

2012年(14)

2011年(42)

2010年(18)

2009年(78)

2008年(35)

2007年(182)

2006年(92)

我的朋友

分类: LINUX

2007-11-07 15:25:44

我这里所谓的宽带实在太慢了(对比以前在北海几M的下载速率……),今天想用wget抓几个网页文档下来离线阅读,那堆选项实在麻烦,而且不好维护更新什么的。干脆自己用脚本调用它写了一个……
用法:
getmirror dir xxxx:指定网页存放和维护的主目录。默认是$HOME/webmirror
getmirror add xxxx:增加一个感兴趣的站到列表。
getmirror ud:更新站点列表到主目录。
getmirror [-d directory] xxxx 直接下载网站镜像到指定目录,不指定就使用当前目录。
写得比较瓜……以后还要优化……成熟了之后改用GUI写或者写个firefox的扩展什么的……

准备增加的:
getmirror remove xxxx
getmirror cron
getmirror uncron

可能以后要改成:
getmirror -d xxx -u xxxx -name xxxx指定一个站点的名字以便维护,update或者remove什么的。

脚本如下:

# !/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




把它放在/usr/sbin/里面加上执行权限就行鸟……
我的习惯是把自己写的脚本放在$HOME/.myscript然后PATH=${PATH}:${HOME}/.myscript
阅读(651) | 评论(0) | 转发(0) |
0

上一篇:Linux 服务器安全配置

下一篇:LINUX下防DDOS

给主人留下些什么吧!~~