Last active
June 6, 2017 01:33
-
-
Save mitcdh/e2af3f537a9c82df76bf5bfad7c12977 to your computer and use it in GitHub Desktop.
Bash function to generate Junos address book entries
This file contains 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
# e.g. host2j google.com [..] TRUST | |
# e.g. jhostset google.com [..] google-servers TRUST | |
function host2j() | |
{ | |
ZONENAME="${@: -1}" | |
for HOSTNAME in "$@" | |
do | |
if [ "$HOSTNAME" != "$ZONENAME" ] | |
then | |
host ${HOSTNAME} | perl -pe "s/(\w+)[\w\.]+ has address ([\d\.]+)/set security zones security-zone ${ZONENAME} address-book address host_\\1 \\2\/32/" | |
fi | |
done | |
} | |
function jhostset() | |
{ | |
GROUPNAME="${@: -2:1}" | |
ZONENAME="${@: -1}" | |
for HOSTNAME in "$@" | |
do | |
if [ "$HOSTNAME" != "$GROUPNAME" ] && [ "$HOSTNAME" != "$ZONENAME" ] | |
then | |
echo "set security zones security-zone ${ZONENAME} address-book address-set ${GROUPNAME} address host_${HOSTNAME}" | |
fi | |
done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment