最近的爬虫是在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. caffe生成log日志

    参考日志: http://blog.csdn.net/sunshine_in_moon/article/details/53529028 http://blog.csdn.net/lishanlu13 ...

  2. vue select中的option循环的时候,要使用 :value,不能使用 v-model

    <select class="classColor" @change="select" v-model="selectValue"&g ...

  3. php字段转义

    addslashes() 函数返回在预定义的字符前添加反斜杠的字符串. 预定义字符是:在以下符号前加/ 单引号(') 双引号(") 反斜杠(\) NULL parse_str($str,$a ...

  4. 【洛谷p1601】A+B Problem(高精)

    高精度加法的思路还是很简单容易理解的 A+B Problem(高精)[传送门] 洛谷算法标签: 附上代码(最近懒得一批) #include<iostream> #include<cs ...

  5. Python图片缩放

    from PIL import Image def size(jpg,now_size): im = Image.open(jpg) width, height = im.size if width& ...

  6. HBase之六:HBase的RowKey设计

    数据模型 我们可以将一个表想象成一个大的映射关系,通过行健.行健+时间戳或行键+列(列族:列修饰符),就可以定位特定数据,Hbase是稀疏存储数据的,因此某些列可以是空白的, Row Key Time ...

  7. Redis与memchache对比

    Redis是NOSQL系统之一,它是一个key-value存储系统.和Memcache类似,但很大程度补偿了Memcache的不足,它支持存储的value类型相对更多,包括string.list.se ...

  8. hdu-6397-容斥

    Character Encoding Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Oth ...

  9. POJ2393奶酪工厂

    Yogurt factory Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 14771   Accepted: 7437 D ...

  10. Pandas初学者代码优化指南

    原文:A Beginner’s Guide to Optimizing Pandas Code for Speed 作者:Sofia Heisler 翻译:无阻我飞扬 摘要:Pandas 是Pytho ...