zoukankan      html  css  js  c++  java
  • 一个在linxu自动切换ip的脚本

    最近的爬虫是在linux下运行的,使用的是云立方的代理服务器,需要自动切换一下ip。

    #!/bin/bash
    # coding:utf8

    aa="sources.list"

    #主流程
    if [ -n $aa ];then
    touch $aa
    echo "1->ali(ubuntu16) 2->ali(ubuntu14) 3->nyist(ubuntu14)"
    echo "choose :"
    read sou_name #由键盘读入源类型,切换源

    if [ "$sou_name" = 1 ];then
    echo "${aa}文件已经创建完毕。。。开始写入${sou_name}源地址"
    echo "deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse " >> $aa
    echo "deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse" >> $aa
    echo "deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse" >> $aa
    echo "deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse" >> $aa
    echo "deb http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse" >> $aa

    elif [ "$sou_name" = 2 ];then
    echo "${aa}文件已经创建完毕。。。开始写入${sou_name}源地址"
    echo "deb http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse" > $aa
    echo "deb http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse" >> $aa
    echo "deb http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse" >> $aa
    echo "deb http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse" >> $aa
    echo "deb http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse" >> $aa

    elif [ "$sou_name" = 3 ];then
    echo "${aa}文件已经创建完毕。。。开始写入${sou_name}源地址"
    echo "deb http://59.69.128.21/ubuntu/ trusty main restricted universe multiverse" > $aa
    echo "deb http://59.69.128.21/ubuntu/ trusty-security main restricted universe multiverse" >> $aa
    echo "deb http://59.69.128.21/ubuntu/ trusty-updates main restricted universe multiverse" >> $aa
    echo "deb http://59.69.128.21/ubuntu/ trusty-proposed main restricted universe multiverse" >> $aa
    echo "deb http://59.69.128.21/ubuntu/ trusty-backports main restricted universe multiverse" >> $aa
    else
    exit 1
    fi
    rm -rf /etc/apt/sources.list
    mv $aa /etc/apt/
    else
    echo "error"
    fi

    #测试写入源是否成功
    if test -s /etc/apt/sources.list;then
    cat /etc/apt/sources.list
    apt-get update

    echo "Do you need to upgrade the software? y/n"
    read option
    if [ "$option" = 'y' ];then
    apt-get upgrade -y
    else
    echo "not upgrade"
    fi
    else
    echo "empty"
    fi

    情不知所起一往而深
  • 相关阅读:
    《.NET分布式应用程序开》读书笔记 第一章:理解分布式架构
    一个DataSet的工具类,可以将DataTime的Time部分去掉,主要在序列化Xml时有用.
    Microsoft SQL Server 2005技术内幕系列书籍
    COM+客户端部署发现
    PowerDesigner中三种模型的转换关系图
    将ASP.NET页面内容输出到字符串中
    在WinForms中隐藏Crystal Report的[MainReport]标签页
    qmake常用语法一
    MinGW简介
    Qt的prx文件
  • 原文地址:https://www.cnblogs.com/xingbiaoblog/p/7846736.html
Copyright © 2011-2022 走看看