最近的爬虫是在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

一个在linxu自动切换ip的脚本的更多相关文章

  1. window自动切换ip的脚本

    因为总要切换ip,所以百度了一下脚本 如下http://jingyan.baidu.com/article/d2b1d1029d21b95c7e37d4fa.html 动态ip netsh inter ...

  2. 写一个shell,自动执行jmeter测试脚本

    贡献一个自己写的shell脚本,很简单,但又可以高效率的自动执行jmeter压测脚本. #!/bin/bash #author:zhangyl #version:V1 #该脚本放置于压测脚本的上一层目 ...

  3. Ubuntu 设定壁纸自动切换的shell脚本

    升级到Ubuntu14.04后,感觉bug的确比12.04少多了.顶部任务栏支持半透明效果,所以整个桌面也看上去漂亮了很多.这样的桌面也是值得瞎捣鼓一下的,想到换壁纸,但是没找到设定动态更换壁纸的选项 ...

  4. 一个简单爬免费代理IP的脚本

  5. 【我们开发有力量之二】利用javascript制作批量网络投票机器人(自动改IP)

    帮朋友忙网络投票,粗粗地看了下,投票没有什么限制,仅有一个ip校验:每天每个ip仅能投票一次. 也就是说,可以写一个程序,自动更换IP地址(伪造IP地址),实现批量刷票的目的.于是我写了一个投票机器人 ...

  6. IP自动切换脚本

    @echo off & cls & color 47 & mode con cols=80 lines=25 & title [IP自动切换工具]clsecho. ec ...

  7. 脚本设置IP bat 命令行设置自动获取IP和固定IP

    由于办公室网络需要固定IP和DNS才能上网, 在连接公共网络或者家里又需要自动获取IP和DNS才能上网. 频繁手动切换很麻烦,就搞了两个脚本一键设置. 1.新建文本文件, 命名为固定IP.bat 复制 ...

  8. Nginx+keepalived 脚本安装主从双机热备自动切换解决方案

    Nginx+keepalived 脚本安装主从双机热备自动切换解决方案 2013-07-02 19:24:13 标签:filesnginx keepalived 原创作品,允许转载,转载时请务必以超链 ...

  9. windows10 自动配置切换IP

    办公室与家里的ip网段不一样.每次都要来回修改本地无线WLAN IP段.写了个脚本bat,自动配置WLAN IP,方便切换. 建立 auto-set-ip.bat,保存格式需为ANSI,否则中文会乱码 ...

随机推荐

  1. 比对软件之STAR的使用方法

    建索引 普通比对 二次比对 用于cufflinks和stringtie的比对 待续~ 参考:比对软件STAR的简单使用

  2. Sparksql的内置函数的使用以及案例

    开发环境:spark:2.2.0 工具:IDEA OS:Windows 数据文件: 001E8CB5AB11,ASUSTek,2018-07-12 14:00:57,2018-07-12 14:00: ...

  3. Linux网桥配置

    CentOS:1.配置临时网桥,重启后风格配置丢失[root@CentOS ~]# yum -y install bridge-utils[root@CentOS ~]# brctl addbr br ...

  4. python3-知识扩展扫盲易忘-generator的用法

    前部分转自: https://www.cnblogs.com/Tsukasa/p/6613934.html 通过列表list生成器,我们可以直接创建一个列表 ? 1 2 3 >>> ...

  5. LeetCode--349--两个数组的交集

    问题描述: 给定两个数组,编写一个函数来计算它们的交集. 示例 1: 输入: nums1 = [1,2,2,1], nums2 = [2,2] 输出: [2] 示例 2: 输入: nums1 = [4 ...

  6. 51Nod 1810 连续区间

    https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1810 题目给出一个1~n的排列,问有多少连续区间.连续区间的定义为区间 ...

  7. python_递归实现汉诺塔 (string类型的指针出错 未解决)

    在递归的时候,和数学的归纳法一致. void func( mode) { if(endCondition) { constExpression //基本项 } else { accumrateExpr ...

  8. 发送http请求,get和post两种请求方式

    GET请求 GetMethod getMethod=null; String datas = "json=" + plain; HttpClient httpClient = ne ...

  9. sql百万级查询优化(转)

    < 数据库技术内幕 > 处理百万级以上的数据提高查询速度的方法: 1.应尽量避免在 where 子句中使用!=或<>操作符,否则将引擎放弃使用索引而进行全表扫描. 2.对查询进 ...

  10. mongodb副本集用户权限设置

     mongodb副本集用户权限设置  用户权限参考文章 一:先看看MongoDB中用户的角色说明 read :   数据库的只读权限,包括: aggregate,checkShardingIndex, ...