script_tool_for_linux.bash: Linux 环境下的 hosts 一键部署脚本

 更新时间:2016年04月17日 16:34:10   投稿:mdxy-dxy  
这篇文章主要介绍了script_tool_for_linux.bash: Linux 环境下的 hosts 一键部署脚本,需要的朋友可以参考下

Linux 环境下的 hosts 一键部署脚本,由 @lstoars 贡献; @fluviusmagnus 提供增强版本。

官方网站:https://github.com/racaljk/hosts/tree/master/hosts_tools

#!/bin/sh
#
# script_tool_for_linux
#
# Use command: `sudo sh script_tool_for_linux.sh` or
#    `su -c 'sh script_tool_for_linux.sh'`
# to update your hosts file.
#
# WARNING: the script CAN NOT replace others' hosts rules.
#   If you have hosts rules provided by others, you may get conflict.
#
if [ `id -u` -eq 0 ]; then
 curl -fLo /tmp/fetchedhosts 'https://raw.githubusercontent.com/racaljk/hosts/master/hosts'
 sed -i '/# Copyright (c) 2014/,/# Modified hosts end/d' /etc/hosts

 sed -i "s/localhost/`hostname`/g" /tmp/fetchedhosts

 cat /tmp/fetchedhosts >> /etc/hosts
 rm -f /tmp/fetchedhosts

 echo 'Success.'
else
 echo 'Permission denied, are you root?'
fi

相关文章

  • Shell中字符串排序的几种方法

    Shell中字符串排序的几种方法

    今天小编就为大家分享一篇关于Shell中字符串排序的几种方法,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧
    2019-03-03
  • Git Tag 标签详解

    Git Tag 标签详解

    这篇文章主要介绍了Git Tag 标签以及git命令之git tag给当前分支打标签的相关知识,需要的朋友可以参考下
    2017-11-11
  • Shell脚本获取国内各大运营商网段脚本分享

    Shell脚本获取国内各大运营商网段脚本分享

    这篇文章主要介绍了Shell脚本获取国内各大运营商网段脚本分享,本文使用亚太地区网络信息记录作为数据源,然后使用Shell脚本分析国内的网段,需要的朋友可以参考下
    2014-12-12
  • linux中批量修改文件名的脚本代码

    linux中批量修改文件名的脚本代码

    linux中批量修改文件名的脚本代码,主要是使用了rename,结合shell,喜欢的朋友可以参考下
    2013-01-01
  • Linux中sftp常用命令整理

    Linux中sftp常用命令整理

    sftp命令是一款交互式的文件传输程序,不仅对传输的所有信息使用ssh加密,它还支持公钥认证和压缩等功能。这篇文章整理了Linux中sftp的常用命令,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2022-06-06
  • linux Nginx 日志脚本

    linux Nginx 日志脚本

    这篇文章主要介绍了nginx日志切割脚本、nginx日志分析脚本等,需要的朋友可以参考下
    2013-11-11
  • 一天一个shell命令 linux好管家-进程-ps命令详解

    一天一个shell命令 linux好管家-进程-ps命令详解

    这篇文章主要介绍了一天一个shell命令 linux好管家-进程-ps命令详解 ,需要的朋友可以参考下
    2016-06-06
  • Linux共享内存实现机制的详解

    Linux共享内存实现机制的详解

    这篇文章主要介绍了Linux共享内存实现机制的详解的相关资料,需要的朋友可以参考下
    2017-07-07
  • 一个ping检测告警函数代码

    一个ping检测告警函数代码

    一个ping脚本,服务器通用告警函数。在没有 nagios 的情况下,这个暂且可以用来作为服务器告警使用
    2013-02-02
  • 浅谈Vim中的Tab与空格缩进

    浅谈Vim中的Tab与空格缩进

    下面小编就为大家带来一篇浅谈Vim中的Tab与空格缩进。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2017-05-05

最新评论