watch_1394 发表于 2005-3-5 18:40:58

download.sh

我用的是LumaQQ,下载的时候老是有"Service Temporarily Unavailable"的信息,而我自己只有wget这个下载工具,所以我就自己写了个脚本,让机器自己去下载。而我现在正好在学习bash script,就贴出来,希望大家指教指教。
#!/bin/bash

PATCH=$1
E_WRONG_ARGU=65
E_NOT_LOCATE=66
tracelog=/tmp/tracelog.`date +%d.%m.%Y`

trap clean 2 3 15

clean() {
rm -rf $tracelog 2>/dev/null
exit 1
}

if [ "$#" != 1 ]
then
echo "Usage: `basename $0` file"
exit $E_WRONG_ARGU
fi

PATCH_1=${PATCH#*://}
HOST=${PATCH_1%%/*}
/usr/sbin/traceroute -m 5 $HOST >>$tracelog 2>&1
if grep "unknown host" $tracelog >/dev/null 2>&1
then
echo "Couldn't locate $HOST..."
exit $E_NOT_LOCATE
fi

echo -n -e "The directory where the file is to be placed [/tmp]: "
read DIREC
if [ "$DIREC" = "" ]
then
DIREC="/tmp"
cd $DIREC
else
cd $DIREC
if [ "$?" != 0 ]
then
    echo "$DIREC does not exist, placing in /tmp anyway"
    DIREC="/tmp"
    cd $DIREC
fi
fi

while :
do
wget -c $PATCH
[ "$?" -eq 0 ] && break
done

echo -n -e "remove the log file? [y...n]: "
read ANS
case $ANS in
y|Y) rm -rf $tracelog.$$ 2>/dev/null;;
    *) ;;
esac

exit 0

BOoRFGOnZ 发表于 2005-3-6 07:32:13

楼主检验 程序 加注释 无误后 放到
Shell 脚本欣赏区

以后 都可以放到 那里    谢谢 :D
页: [1]
查看完整版本: download.sh