定期更新github相关hosts

github一些基友的分享

  • https://github.com/maxiaof/github-hosts

  • https://hosts.gitcdn.top/hosts.txt

  • https://raw.githubusercontent.com/maxiaof/github-hosts/master/hosts

  • 这些基友本身已经写好工具定期更新了 直接使用即可 可手工也可用工具自动

自动化工具体验

  • 地址
    • https://github.com/Licoy/fetch-github-hosts
    • https://github.com/Licoy/fetch-github-hosts/releases

使用方法

  • curl获取所有hosts

  • 脚本更新/etc/hosts文件

  • 重启nscd

  • 汇总后的脚本

    #!/bin/bash
    # 拉起githubhosts 检查文件中是否存在指定字样 校验是否拉取成功
    curl -s https://hosts.gitcdn.top/hosts.txt >/tmp/githubhosts.txt
    if grep -q "fetch-github-hosts" /tmp/githubhosts.txt; then
        echo "hello"
    else
        exit 0
    fi
    # 删除/etc/hosts文件中旧的github记录
    # 指定开始和结束标记
    begin_marker="# fetch-github-hosts begin"
    end_marker="# fetch-github-hosts end"
    # 临时文件路径
    temp_file="/tmp/hosts_temp"
    # 复制除了指定行之外的所有行到临时文件
    sed "/$begin_marker/,/$end_marker/d" /etc/hosts > "$temp_file"
    # 将临时文件复制回原始文件
    sudo cp "$temp_file" /etc/hosts
    # 删除临时文件
    rm "$temp_file"

    #追加最新的hosts
    sudo sh -c 'cat /tmp/githubhosts.txt >> /etc/hosts'

    #刷新 DNS
    sudo systemctl restart nscd
  • 添加crontab每小时执行一次

    • 0 * * * * /home/ubuntu/shell/updateGithubHosts.sh > /home/ubuntu/shell/updateGithubHosts.log 2>&1

本文由 mdnice 多平台发布

相关推荐

  1. 定期更新github相关hosts

    2024-07-14 16:00:02       23 阅读
  2. C语言相关知识点(不定期更新内容)

    2024-07-14 16:00:02       22 阅读
  3. Figma host相关设置

    2024-07-14 16:00:02       29 阅读
  4. (持续更新中)DRF相关

    2024-07-14 16:00:02       33 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-14 16:00:02       67 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-14 16:00:02       72 阅读
  3. 在Django里面运行非项目文件

    2024-07-14 16:00:02       58 阅读
  4. Python语言-面向对象

    2024-07-14 16:00:02       69 阅读

热门阅读

  1. 前端面试题日常练-day86 【面试题】

    2024-07-14 16:00:02       16 阅读
  2. 机器学习之常用优化器

    2024-07-14 16:00:02       25 阅读
  3. C++常用算法的简单总结

    2024-07-14 16:00:02       25 阅读
  4. 渗透测试 —— 揭开数字安全的隐形面纱

    2024-07-14 16:00:02       20 阅读
  5. Linux设置开机自启动脚本

    2024-07-14 16:00:02       27 阅读
  6. Visual Studio 配置记录 - 备忘

    2024-07-14 16:00:02       20 阅读
  7. P3743 小鸟的设备

    2024-07-14 16:00:02       20 阅读