onttpi 发表于 2008-6-9 01:12

[SHELL we talk 之六] 下载完成后关机

最近天气热,Ubuntu下花了两次屏...

常要下些东西,等它下完再关机,这个在WIN下用迅雷很简单。
但linux下的一些下载工具却没这功能...
我常用的命令是 wget ..
wget -b -c http://xxx.xxx.xxx/xxx
这样就会产生一个wget-log文件记录下载记录(如果wget-log已存在会后面加数字1,wget-log1存在则生成wget-log2,依此类推)
log文件的内容里有下载的百分比
要实现下载完毕关机我们只要用到两个命令:查看文件内容和关机

tail (因为log文件是追加形式生成的) 和 shutdown
#!/bin/sh
# @desciption:
#      test weather the wget's log contains 100%
#      if true then bell and exit
#      else sleep some seconds for next test
#@useage:
#      testDone ]
#            log_file_name default for "~/downloads/wget-log
#            wait_seconds default for 10 seconds
#   @notice
#         there's not any error detemin in this script
#
if [ $# -gt 0 ]
    then
      echo "you would like to test $1"
      filename="$HOME/downloads/$1"
      if [ $# -gt 1 ]
         then
            sleeptime=$2
      else
            sleeptime=10
      fi
else
    filename="$HOME/downloads/wget-log"
    sleeptime=10
fi

#echo $filename

while [ "1" = "1" ]
do
tail$filename |grep "100%"   >/dev/null
if [ $? != "1" ]
    then
      echo "done.. ...exiting...\c"
      init 0      # or use shutdown
      break
fi
#echo "not down..\n"
sleep$sleeptime
done





[ 本帖最后由 onttpi 于 2008-6-9 15:08 编辑 ]

hjack 发表于 2008-6-9 01:22

代码呢??

onttpi 发表于 2008-6-9 02:07

原本只是要做成完成就响铃,所以说明与代码有所不符...

onttpi 发表于 2008-6-9 02:08

HJACK改成下载多个文件时全部下完再关机..

hjack 发表于 2008-6-12 20:25

忘了wget的log文件格式是怎么样的了。。
页: [1]
查看完整版本: [SHELL we talk 之六] 下载完成后关机