Created
October 30, 2013 06:14
-
-
Save juanvgarcia/7227899 to your computer and use it in GitHub Desktop.
This a very simple script that will comment host names depending on their initial numbering. My home network setup is different than my home's, and therefore I use this script to change the hostnames I use for development testing purposes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
if [ "$1" != "work" ] && [ "$1" != "home" ]; | |
then | |
echo "Wrong arguments Usage: $0 home|work" | |
exit 65 | |
fi | |
work_test_regex="^10" | |
home_test_regex="^192" | |
work_off_regex="/^10/#10/g" | |
work_on_regex="/^#10/10/g" | |
home_off_regex="/^192/#192/g" | |
home_on_regex="/^#192/192/g" | |
if [ "$1" == "work" ]; | |
then | |
work_test=`grep $work_test_regex /etc/hosts` | |
if [ -z "$work_test" ]; | |
then | |
sed -i.bak "s$work_on_regex" /etc/hosts | |
sed -i.bak "s$home_off_regex" /etc/hosts | |
else | |
echo "Aborting switch to work mode since work mode seems to be activated." | |
exit 1 | |
fi | |
else | |
home_test=`grep $home_test_regex /etc/hosts` | |
if [ -z "$home_test" ]; | |
then | |
sed -i.bak "s$home_on_regex" /etc/hosts | |
sed -i.bak "s$work_off_regex" /etc/hosts | |
else | |
echo "Aborting switch to home mode since home mode seems to be activated." | |
exit 1 | |
fi | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Since `$work_test isn't used, it might be easier to read with just:
A cleaner way to use
if
with exit status, just a small suggestion.