hatcloud
V2EX  ›  Unix

怎么写 Mac 下的脚本?

  •  
  •   hatcloud · Oct 25, 2014 · 11455 views
    This topic created in 4392 days ago, the information mentioned may be changed or developed.
    自己想写一个自动从GitHub上更新最新的Hosts文件到本地的脚本,奈何完全不会Unix的脚本编写。
    希望诸位能提供个简单教程的网页
    或者直接帮我写一个吧(不会被说伸手党吧)

    在终端自己输入的命令如下:
    cd 本地的Git文件夹路径
    git pull
    sudo cp imouto.host.txt /etc/hosts
    Supplement 1  ·  Oct 25, 2014
    脚本写好了,果然只要吧命令行一条条列出来就行了

    附上脚本内容及GitHub地址:

    -------文件名---------
    updateHosts.sh

    -------文件内容----------
    #! /bin/bash
    cd /Users/Jeff/Documents/Git/imouto.host
    git pull
    sudo cp imouto.host.txt /etc/hosts



    我在用的hosts地址:https://github.com/zxdrive/imouto.host
    蛮好用的,基本Google,FB,Twitter等都不用GoAgent,VPN了
    Supplement 2  ·  Oct 25, 2014
    现在要做的就是把这个脚本定时运行,这个还得去查查看
    9 replies  •  2014-10-25 15:16:50 +08:00
    hjc4869
    hjc4869
    Oct 25, 2014
    1
    学一下bash脚本,挺容易的。
    hatcloud
    hatcloud
    OP
    Oct 25, 2014
    2
    @hjc4869 我去搜搜看
    Busy
    Busy
    Oct 25, 2014
    3
    三个命令写成三行,放入一个文件中,给他执行权限,不就一个脚本嘛
    看下 shell 相关的知识
    hatcloud
    hatcloud
    OP
    Oct 25, 2014
    4
    @Havee 不用加什么失败判断什么的么...不过我去试试
    Livid
    Livid
    MOD
    PRO
    Oct 25, 2014
    5
    你可以考虑先稍微学一下 vi 编辑器。
    banbanchs
    banbanchs
    Oct 25, 2014
    6
    wget rawgithubXXX -O /etc/hosts
    加到crontab,要root权限
    hatcloud
    hatcloud
    OP
    Oct 25, 2014
    7
    @Livid 再用vi,可是vi和这个有什么关系吗?
    Vicia
    Vicia
    Oct 25, 2014
    8
    Keyboard Maestro可以定时运行脚本。
    skydiver
    skydiver
    Oct 25, 2014 via Android
    9
    直接软链到/etc/hosts就行了,以后每次pull
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   5094 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 52ms · UTC 07:38 · PVG 15:38 · LAX 23:38 · JFK 02:38
    ♥ Do have faith in what you're doing.