工大后院

 找回密码
 加入后院

扫一扫,访问微社区

QQ登录

只需一步,快速开始

搜索
查看: 3419|回复: 4

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

[复制链接]
发表于 2008-6-9 01:12 | 显示全部楼层 |阅读模式
最近天气热,Ubuntu下花了两次屏...

常要下些东西,等它下完再关机,这个在WIN下用迅雷很简单。
但linux下的一些下载工具却没这功能...
我常用的命令是 wget ..

  1. wget -b -c http://xxx.xxx.xxx/xxx
复制代码
这样就会产生一个wget-log文件记录下载记录(如果wget-log已存在会后面加数字1,wget-log1存在则生成wget-log2,依此类推)
log文件的内容里有下载的百分比
要实现下载完毕关机我们只要用到两个命令:查看文件内容和关机

tail (因为log文件是追加形式生成的) 和 shutdown

  1. #!/bin/sh
  2. # @desciption:
  3. #        test weather the wget's log contains 100%  
  4. #        if true then bell and exit
  5. #        else sleep some seconds for next test
  6. #  @useage:
  7. #        testDone [log_file_name [wait seconds]  ]
  8. #              log_file_name default for "~/downloads/wget-log
  9. #              wait_seconds default for 10 seconds
  10. #   @notice
  11. #         there's not any error detemin in this script
  12. #
  13. if [ $# -gt 0 ]
  14.     then
  15.         echo "you would like to test $1"
  16.         filename="$HOME/downloads/$1"
  17.         if [ $# -gt 1 ]
  18.            then
  19.             sleeptime=$2
  20.         else
  21.             sleeptime=10
  22.         fi
  23. else
  24.     filename="$HOME/downloads/wget-log"
  25.     sleeptime=10
  26. fi

  27. #echo $filename

  28. while [ "1" = "1" ]
  29. do
  30.   tail  $filename |  grep "100%"   >/dev/null
  31.   if [ $? != "1" ]
  32.     then
  33.         echo "done.. ...exiting...\c"
  34.         init 0      # or use shutdown
  35.         break
  36.   fi
  37.   #echo "not down..\n"
  38.   sleep  $sleeptime
  39. done



复制代码

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

评分

2

查看全部评分

发表于 2008-6-9 01:22 | 显示全部楼层
代码呢??
回复

使用道具 举报

 楼主| 发表于 2008-6-9 02:07 | 显示全部楼层
原本只是要做成完成就响铃,所以说明与代码有所不符...

评分

1

查看全部评分

回复

使用道具 举报

 楼主| 发表于 2008-6-9 02:08 | 显示全部楼层
HJACK改成下载多个文件时全部下完再关机..

评分

2

查看全部评分

回复

使用道具 举报

发表于 2008-6-12 20:25 | 显示全部楼层
忘了wget的log文件格式是怎么样的了。。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 加入后院

本版积分规则

QQ|Archiver|手机版|小黑屋|广告业务Q|工大后院 ( 粤ICP备10013660号 )

GMT+8, 2025-5-10 23:20

Powered by Discuz! X3.5

Copyright © 2001-2024 Tencent Cloud.

快速回复 返回顶部 返回列表