Checkpoint Firewall Configuration Backup

#!/bin/bash

# Check Point Firewall Inventory
# dj0Nz Nov 2020

. /opt/CPshared/5.0/tmp/.CPprofile.sh

GW_LIST=(`mgmt_cli -r true show gateways-and-servers limit 500 | egrep -B 1 'ClusterMember|simple-gateway' | grep name | awk '{print $2}' | tr -d '"'`)
PORT=18208

for INDEX in "${GW_LIST[@]}"; do
   # remove nonprintable, otherwise unpredictable results...
   GW=`tr -dc '[[:print:]]' <<< "$INDEX"`
   OPEN=`timeout 3 bash -c "/dev/null &&  echo "Open" || echo "Closed"`
   if [[ "$OPEN" = "Open" ]]; then
      MODEL=`$CPDIR/bin/cprid_util -server $GW -verbose rexec -rcmd clish -c "show asset system" | grep ^Model | awk '{print $2 " " $3 " " $4}'`
      if [ ! "$MODEL" = "" ]; then
         printf "%-17s %s\n" "$GW: " "$MODEL"
      else
         printf "%-17s %s\n" "$GW: " "No Model Info"
      fi
   else
      printf "%-17s %s\n" "$GW: " "Unreachable"
   fi
done