分页: 2 / 4

发表于 : 2006-06-24 11:00
roylez
apt-axel 脚本

这算是个老东西了。作者写了0.1版本之后好像就把它给忘了。它能够实现用多线程下子源里面的东西,虽然比不上bt,但是确实小巧而方便。程序结构很简单,没多少行。可惜我不会bash脚本,哪个大侠把它给改改造福天下?

代码: 全选

#!/bin/bash

###########################################################################
#
# Authors: Jesús Espino García & Lucas García
# Email: jespino@imap.cc
# Date: 31/05/2004
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
###########################################################################

# If the config file not exist, load the default parameters

VERSION="0.1"
CONFIG_FILE="/etc/apt-axel.conf";

if [ -f $CONFIG_FILE ]; then
  . $CONFIG_FILE 
else
  # Verbose TRUE or FALSE
  VERBOSE="FALSE"

  # Conections
  CONNECTIONS=8

  # Servers
  server1="ftp://ftp.de.debian.org/debian/"
  server2="ftp://ftp.es.debian.org/debian/"
  server3="ftp://ftp.fr.debian.org/debian/"
  server4="ftp://ftp.it.debian.org/debian/"
  server5="ftp://ftp.fi.debian.org/debian/"
  server6="ftp://ftp.uk.debian.org/debian/"
  server7="ftp://ftp.tk.debian.org/debian/"
  server8="ftp://ftp.us.debian.org/debian/"
fi

# Set the package variable to be global
package="";

# Show the help
mostrar_ayuda() {
  echo "Usage: apt-axel <option> <package>";
  echo "";
  echo "Options:";
  echo "  install - Install new packages (paquete es libc6 y no libc6.deb)";
  echo "  upgrade - Do a software upgrade";
  echo "  dist-upgrade - Do a distribution upgrade, see apt-get(8)";
  echo "  --version - Print the current version of apt-axel";
  echo "  --help - Show this help";
  echo "";
}

# Get a package from the ftp server
get_package() {
  descargar() {
    # Check the $VERBOSE variable and the filesize, if the filesize is lower than 200K will use only 4 conections
    # And if the $VERBOSE variable is TRUE, then print the axel output
    if [ $VERBOSE == "TRUE" ]; then
      if [ $size -gt 200000 ]; then
        axel -a -n $CONNECTIONS $server1$url $server2$url $server3$url $server4$url \
          $server5$url $server6$url $server7$url $server8$url -o /tmp/$archivo
      else
        axel -a -n 4 $server1$url $server2$url $server3$url $server4$url $server5$url \
          $server6$url $server7$url $server8$url -o /tmp/$archivo
      fi
    else
      echo -n "Geting $package package: "
      if [ $size -gt 200000 ]; then
        axel -a -n $CONNECTIONS $server1$url $server2$url $server3$url $server4$url \
          $server5$url $server6$url $server7$url $server8$url -o /tmp/$archivo > /dev/null
      else
        axel -a -n 4 $server1$url $server2$url $server3$url $server4$url $server5$url \
          $server6$url $server7$url $server8$url -o /tmp/$archivo > /dev/null
      fi
      echo "Done"
    fi
  }

  # Getting data
  url=$(apt-cache show $package | grep ^Filename: | sed s/^Filename:\ //)
  archivo=$(echo "$url" | sed s/^.*$package/$package/)
  pkgstatus=$(dpkg -s $package 2> /dev/null | grep ^Status: | grep -v "not-installed")
  md5sum=$(apt-cache show $package | grep ^MD5sum: | sed s/^MD5sum:\ //)
  size=$(apt-cache show $package | grep ^Size: | sed s/^Size:\ //)
  
  # Downloading the package
  if [ -f /var/cache/apt/archives/$archivo ]; then
    echo -n "Package already downloaded. Checking md5sum of $package package: "
    while [ $md5sum != $(md5sum /var/cache/apt/archives/$archivo | sed s/\ .*$//) ]; do 
      echo "incorrect"
      echo "Downloading again $package package."
      rm -f /var/cache/apt/archives/$archivo
      descargar
    done
    echo "correct"
  else
      descargar
  fi

  # Move the file to /var/cache/apt/archives
  if [ -f /tmp/$archivo ]; then
    if [ $md5sum == $(md5sum /tmp/$archivo | sed s/\ .*$//) ]; then
      mv -f /tmp/$archivo /var/cache/apt/archives/
    fi
  fi
}

pkg_install() {
  for package in $(apt-get -s install $1 | grep ^Inst\ | sed s/^Inst\ // | sed s/\ .*$//); do
    get_package
  done
  apt-get -y install $1
}

upgrade() {
  for package in $(apt-get -s upgrade | grep ^Inst\ | sed s/^Inst\ // | sed s/\ .*$//); do
    get_package
  done
  apt-get -y upgrade
}

dist_upgrade() {
  for package in $(apt-get -s dist-upgrade | grep ^Inst\ | sed s/^Inst\ // | sed s/\ .*$//); do
    get_package
  done
  apt-get -y dist-upgrade
}


#
# Main program
#
if [ `id -u` != 0 ]; then
  echo "You must be root to run this command."
else
  case $1 in
    install) pkg_install $2;;
    upgrade) upgrade;;
    dist-upgrade) dist_upgrade;;
    (--version) echo "Current Version: $VERSION";;
    (--help | -h) mostrar_ayuda;;
    *) mostrar_ayuda;;
  esac
fi

[讨论]

发表于 : 2006-07-10 11:12
tcj1213
请问:如何用SHELL实现一个字符串分解,文件的读取的小程序?

发表于 : 2006-11-19 23:10
xdsnet
字符串分解一般可以利用grep/sed/awk等工具,其实sed和awk本身也具有语言特性,可以支持编程的,特别是awk功能很强大的。
我看了前面的帖子,很多是因为对shell没有太多的了解,我想大家可以考虑应该增加这方面的知识。
此外我想楼主的意思是可以在这个帖子中收集大家的一些困难,大家一起来找解决方案,所以最好明确自己的目的,如果确实需要明确的解决方法,就要提出明确的需求,这样别人才能具体问题具体分析,帮你找到方法啊。所以还是请大家先看看《提问的智慧》一文。

[问题]如何实现ubuntu启动的时候自动查询ip并mail到指定信

发表于 : 2006-11-21 18:09
cottonsweet
本人是彻底的linux新手,呵呵,因为计算需要才装了ubuntu。想实现远程登录操作机器,
但是这里的ip地址是动态分配的,如何才能实现在启动的时候,自动获取ip信息,然后发
送到指定信箱?需要使用那些命令来实现这样一个shell脚本?谢谢

发表于 : 2006-12-08 19:08
KyTor
纯粹支持!

发表于 : 2006-12-21 23:00
Tenyears
怎么实现这样的备份:
两台机器:实验室,家。

希望同步两台机器的主目录数据,或者包括系统一起。

比如,晚上回家时,把一天的增量备份到优盘,回家后通过优盘使家里机器和实验室同步。

有可能怎么实现?给个点子。

[报到]

发表于 : 2007-03-09 23:11
etheng
Tenyears 写了:怎么实现这样的备份:
两台机器:实验室,家。

希望同步两台机器的主目录数据,或者包括系统一起。

比如,晚上回家时,把一天的增量备份到优盘,回家后通过优盘使家里机器和实验室同步。

有可能怎么实现?给个点子。
check out "rsyn". Assuming you want to update your homePC to your labPC. At your homePC run this command. This example also assume that both PC has the same UID.

# rsync -avz /data/ lapPC:/data

*** I do not have chinese input software at the moment, so if there are any kind soul please help to translate.

发表于 : 2007-04-01 11:37
风飘雨
怎样用shell写一个完成双机热备份的脚本?或者提供一个其他的解决方案?如果能应用于集群最好,



然后一个简单点的,,通过一个配置文件来限定某些ip或者ip段(v4 &v6)在特定时间内访问计算机?比如一个程序只需要将一个ip写入这个文件,系统会立刻自动禁止这个ip的所有访问20分钟,之后会自动解除限制,(这个好像通过iptable能做到,但需要的就是动态更改规则的脚本,并且尽可能少的占用资源。)

发表于 : 2007-04-29 19:27
XDG3669
可不可以写个脚本:在同一目录中复制生成另外一个文件需要弹出对话框以方便改名?

发表于 : 2007-05-12 20:52
gsli52
谢谢,本人初学
需xrgsu的上网脚本
可以把
ifconfig eth0 x.x.x.x
xrgsu -d
一起启动,并通过修改脚本将密码保存在sh文件中

发表于 : 2007-05-13 13:57
antonym55
站内短信没有提供保存到本地的功能,想用wget下载下来,试了一下面的命令, 不过没成功,呵呵

代码: 全选

wget --http-user=antonym55 --http-passwd=****** http://forum.ubuntu.org.cn/privmsg.php?folder=savebox&mode=read&p=26727
需要一个脚本可以把站内的短信保存到本地,

输入用户名和密码,就可以把短信收到本地

发表于 : 2007-06-02 19:59
N0.1
想自己尝试编写一个脚本。。。

实现论坛自动回复功能。。。。

发表于 : 2007-06-08 21:35
marui139980
N0.1 写了:想自己尝试编写一个脚本。。。

实现论坛自动回复功能。。。。
跟我的想法一样 ,我们公司需要在网上回帖签到,我也想编一个 自动回帖功能

发表于 : 2007-07-29 9:45
magiciany
把MP3/WMA的文件名替换为ID3信息,把ID3信息用文件名来填写,类似ttplayer的

求一个能从网页中提取有关信息的脚本或着相关思路

发表于 : 2007-08-02 22:03
zub
本人还是个菜鸟,刚开始学shell,希望哪个大侠能提供一个能从网页中提取有关信息的脚本,或着相关思路,谢谢 :D :D :D