Skip to content

Instantly share code, notes, and snippets.

@crmaxx
Forked from jarlef/update-hosts
Created October 4, 2023 10:27
Show Gist options
  • Select an option

  • Save crmaxx/891d29382f2a7794c5ed637e2bb1ad7f to your computer and use it in GitHub Desktop.

Select an option

Save crmaxx/891d29382f2a7794c5ed637e2bb1ad7f to your computer and use it in GitHub Desktop.

Revisions

  1. @jarlef jarlef revised this gist Jul 17, 2015. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions update-hosts
    Original file line number Diff line number Diff line change
    @@ -13,8 +13,7 @@ case "$1" in
    echo "$IP $2" >> /etc/hosts
    ;;
    remove)
    #sed -ie "\|^$IP $2\$|d" /etc/hosts
    sed -i "/\s$2/d" /etc/hosts
    sed -i "/\s$2/d" /etc/hosts
    ;;

    *)
  2. @jarlef jarlef renamed this gist Jul 17, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. @jarlef jarlef created this gist Jul 17, 2015.
    38 changes: 38 additions & 0 deletions gistfile1.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    #! /bin/sh
    # @author: Jarle Friestad
    # Based on script by Claus Witt (http://clauswitt.com/319.html)

    # Adding or Removing Items to hosts file
    # Use -h flag for help

    DEFAULT_IP=127.0.0.1
    IP=${3:-$DEFAULT_IP}

    case "$1" in
    add)
    echo "$IP $2" >> /etc/hosts
    ;;
    remove)
    #sed -ie "\|^$IP $2\$|d" /etc/hosts
    sed -i "/\s$2/d" /etc/hosts
    ;;

    *)
    echo "Usage: update-hosts COMMAND [args..]"
    echo
    echo "Utility for adding or removing entries in hosts file"
    echo
    echo "Commands:"
    echo " add update-hosts add [hostname] [ip]"
    echo " remove update-hosts remove [hostname]"
    echo
    echo "Ip defaults to 127.0.0.1"
    echo
    echo "Examples:"
    echo " update-hosts add testing.com 127.0.0.2"
    echo " update-hosts remove testing.com"
    exit 1
    ;;
    esac

    exit 0