Skip to content

Instantly share code, notes, and snippets.

@mkol5222
Forked from joe-at-cp/distribute.sh
Created June 27, 2025 11:30
Show Gist options
  • Save mkol5222/a464a99c69abd587dc82104b32ddd3df to your computer and use it in GitHub Desktop.
Save mkol5222/a464a99c69abd587dc82104b32ddd3df to your computer and use it in GitHub Desktop.
File Distribute Script For Check Point Management Servers
#!/bin/bash
#distribute.sh
#Joe Dillig - Check Point Software 2019 - [email protected]
#Script used to distrubute custom dynamic object tracking scripts to managed gateways from the Check Point management server
#Location to transfer files to on each gateway
REMOTE_SCRIPT_DIR="/home/admin/scripts/dynobjs"
#List of files to distribute
FILE_LIST="crl_dyn_objs.sh delete_old_dyn_objs.sh update_dynamic_objs.sh"
#List of managed gateways to distribute to (using management ip)
GATEWAY_LIST="192.168.30.2 10.200.0.130"
tput sgr0
#Distribute scipts to gateways
for GATEWAY in $GATEWAY_LIST
do
tput sgr0
echo "$(tput bold)[+] Gateway: $GATEWAY"
#Create Remote Script Directoy Structure
cprid_util -server $GATEWAY -verbose rexec -rcmd bash -c "mkdir -p $REMOTE_SCRIPT_DIR" > /dev/null
exitcode=$?
if [ $exitcode -ne 0 ]
then
echo "$(tput setaf 1) \__ Script directory structure (failed!)"
else
echo "$(tput setaf 2) \__ Script directory structure (ok)"
fi
for FILE in $FILE_LIST
do
REMOTE_FILE=$REMOTE_SCRIPT_DIR"/"$FILE
#Md5sum of file pre transfer
local_checksum=`md5sum $FILE | awk 'NF {print $1}'`
FILE_XFER=`cprid_util putfile -server $GATEWAY -local_file $FILE -remote_file $REMOTE_FILE -progress`
exitcode=$?
if [ $exitcode -ne 0 ]
then
echo "$(tput setaf 1) \__ $FILE (transfer failed!)"
else
#Md5sum of file post transfer
remote_checksum=`cprid_util -server $GATEWAY -verbose rexec -rcmd bash -c "md5sum $REMOTE_FILE" | awk 'NF {print $1}'`
#Validate local and remote checksums match
if [ $local_checksum == $remote_checksum ]
then
echo "$(tput setaf 2) \__ $FILE ($FILE_XFER bytes transfered - checksum passed)"
else
echo "$(tput setaf 1) \__ $FILE (transfer failed! checksum mismatch)"
echo "$(tput setaf 1) local checksum: $local_checksum"
echo "$(tput setaf 1) remote checksum: $remote_checksum"
fi
fi
done
done
#Backup existing scripts and replace with new
#Verify crontab is up to date
#Exit
tput sgr0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment