Skip to content

Instantly share code, notes, and snippets.

@DarkMukke
Created January 27, 2016 10:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DarkMukke/9f9cd3441c921a272acf to your computer and use it in GitHub Desktop.
Save DarkMukke/9f9cd3441c921a272acf to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
#
# # # example.ini
# [goedhuis-dev]
# USER = juno
# HOST = gh.juno.is
#
# [goedhuis-stag]
# USER = juno
# HOST = ghstaging.juno.is
#
CONFIGFILE="example.ini";
REMOTECOMMAND="ls -All";
_SECTIONS=`cat ${CONFIGFILE} | grep -o -P "\[([a-zA-Z0-9-]+)\]" | tr -d [] | sed ':a;N;$!ba;s/\n/ /g'`
ini_parser() {
FILE=$1
SECTION=$2
eval $(sed -e 's/[[:space:]]*\=[[:space:]]*/=/g' \
-e 's/[;#].*$//' \
-e 's/[[:space:]]*$//' \
-e 's/^[[:space:]]*//' \
-e "s/^\(.*\)=\([^\"']*\)$/\1=\"\2\"/" \
< $FILE \
| sed -n -e "/^\[$SECTION\]/I,/^\s*\[/{/^[^;].*\=.*/p;}")
}
# A sections array that we'll loop through
for SEC in $_SECTIONS; do
ini_parser ${CONFIGFILE} ${SEC};
echo "ssh $USER@$HOST"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment