Created
January 27, 2016 10:46
-
-
Save DarkMukke/9f9cd3441c921a272acf to your computer and use it in GitHub Desktop.
Revisions
-
DarkMukke created this gist
Jan 27, 2016 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,37 @@ #!/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