Skip to content

Instantly share code, notes, and snippets.

@mitcdh
Last active June 6, 2017 01:33
Show Gist options
  • Save mitcdh/e2af3f537a9c82df76bf5bfad7c12977 to your computer and use it in GitHub Desktop.
Save mitcdh/e2af3f537a9c82df76bf5bfad7c12977 to your computer and use it in GitHub Desktop.
Bash function to generate Junos address book entries
# 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