- Products
- Learn
- Local User Groups
- Partners
- More
Quantum Spark Management Unleashed!
Introducing Check Point Quantum Spark 2500:
Smarter Security, Faster Connectivity, and Simpler MSP Management!
Check Point Named Leader
2025 Gartner® Magic Quadrant™ for Hybrid Mesh Firewall
HTTPS Inspection
Help us to understand your needs better
CheckMates Go:
SharePoint CVEs and More!
Hi, i would love if someone can help me with this script. it used for backup clish configuration of all GWs remotely from mgmt, save i to file and upload to ftp server. i guess it's something simple to those familiar with bash more than i do.
it was working fine, by creating seperate file for each gw which GWName_Date.txt filename. but lately (maybe from some ver upgrade) it failed to save the filename with $hostname, so it's only save it with the date like 11.7.21.txt, and this cause that each time it override this file, because all files get the same name. if i just run from mgmt cprid_util -server x.x.x.x -verbose rexec -rcmd /bin/bash -c "hostname" it brings the correct hosname. what can be the problem here? how can i fix it?
thx!
#!/bin/sh
source /opt/CPshrd-R80.40/tmp/.CPprofile.sh
for dest in $(</var/log/scripts/gws_list.txt); do
hostname=`cprid_util -server $dest -verbose rexec -rcmd /bin/bash -c "hostname"`
now=$(date +"%m_%d_%Y").txt
cprid_util -server $dest -verbose rexec -rcmd /bin/clish -c "show configuration" > /var/log/gws_backup/$hostname_$now
done
.........ftp commands.....
rm /var/log/gws_backup/*
#!/bin/bash
source /opt/CPshrd-R80.40/tmp/.CPprofile.sh
while read dest; do
gwhostname=$(cprid_util -server $dest -verbose rexec -rcmd /bin/bash -c "hostname")
now=$(date +"%m_%d_%Y").txt
cprid_util -server $dest -verbose rexec -rcmd /bin/clish -c "show configuration" > /var/log/gws_backup/"$gwhostname"_"$now"
done </var/log/scripts/gws_list.txt
1. replace #!/bin/sh with #!/bin/bash
2. if still not working, try to rename "hostname" with something else, like "gw_hostname" and save it as variable as you have for date:
gw_hostname=$(cprid_util -server $dest -verbose rexec -rcmd /bin/bash -c "hostname")
do not forget to replace new variable of hostname in last cprid_util command
PS: I suggest to do not use exact path, like you have for source command. If you upgrade to another version (to R81.x), you will need to replace the path in the source command (use $FWDIR instead).
Hi,
thank you. here is the script now, but it still do the same thing - ignore the hostname and only writes the date as the filename.
[Expert@fwm-nihuli:0]# cat gws_backup.sh
#!/bin/bash
source /opt/CPshrd-R80.40/tmp/.CPprofile.sh
for dest in $(</var/log/scripts/gws_list.txt); do
gwhostname=$(cprid_util -server $dest -verbose rexec -rcmd /bin/bash -c "hostname")
now=$(date +"%m_%d_%Y").txt
cprid_util -server $dest -verbose rexec -rcmd /bin/clish -c "show configuration" > /var/log/gws_backup/$gwhostname_$now
done
as for the option to run it on every gw. i used to do that, but it's have to maintain. as i have tens of gws.
Is file /var/log/scripts/gws_list.txt present and NOT empty?
are you getting any output from variable "dest" ? try to add "echo $dest" in the loop to see if this will give you desired value (the IPs or hostnames).
Maybe that "for" is not working properly.
Try to use following instead:
while read dest; do
echo "$dest"
. . .
done </var/log/scripts/gws_list.txt
Hi,
thank you so much for your assistance. unfortunately i don't have much knowledge in bash scripts so i don't know how to complete your ". . ." if you can write all the section as it should be so i can copy & paste it, i will appreciate it.
as for the dest, i know it's working in some way because when i tail the output file ($date.txt) whlie it runs i can see that it go over the FWs(IPS) list from the /var/log/scripts/gws_list.txt file(yes it's exist). so the file is replaced but it run on all the gws list and write their configuration to the file.
#!/bin/bash
source /opt/CPshrd-R80.40/tmp/.CPprofile.sh
while read dest; do
echo "$dest"
gwhostname=$(cprid_util -server $dest -verbose rexec -rcmd /bin/bash -c "hostname")
now=$(date +"%m_%d_%Y").txt
cprid_util -server $dest -verbose rexec -rcmd /bin/clish -c "show configuration" > /var/log/gws_backup/$gwhostname_$now
done </var/log/scripts/gws_list.txt
i copied it exactly, and the result is the same. output file name ignoring hostname.
only now when running it, i can see output on the screen with the IP's of the GWs it working on live:
#GWS_list
x.x.x.x
x.x.x.x
x.x.x.x
x.x.x.x
x.x.x.x
it didn't change the result. the only change was that on the window i run the script i see live output that goes line by line from the gws_list.txt file, so i see on which gw it's working at any moment, but the output filename still goes without hostname..
#!/bin/bash
source /opt/CPshrd-R80.40/tmp/.CPprofile.sh
while read dest; do
gwhostname=$(cprid_util -server $dest -verbose rexec -rcmd /bin/bash -c "hostname")
now=$(date +"%m_%d_%Y").txt
cprid_util -server $dest -verbose rexec -rcmd /bin/clish -c "show configuration" > /var/log/gws_backup/"$gwhostname"_"$now"
done </var/log/scripts/gws_list.txt
It worked!
You are the best
Thank you very much
Jozko is 100% right...that was actually first thing I noticed as well. Let us know if that works.
By the way, another way would be to schedule cron job at specific date on every affected gateway to run command "clish -c 'save configuration <PATH>' "
and then just transfer the backup file to ftp server.
There are plenty of options how to reach the goal of every script 🙂
Leaderboard
Epsum factorial non deposit quid pro quo hic escorol.
User | Count |
---|---|
10 | |
8 | |
6 | |
5 | |
5 | |
5 | |
5 | |
5 | |
5 | |
4 |
Wed 03 Sep 2025 @ 11:00 AM (SGT)
Deep Dive APAC: Troubleshooting 101 for Quantum Security GatewaysThu 04 Sep 2025 @ 10:00 AM (CEST)
CheckMates Live BeLux: External Risk Management for DummiesWed 10 Sep 2025 @ 11:00 AM (CEST)
Effortless Web Application & API Security with AI-Powered WAF, an intro to CloudGuard WAFWed 10 Sep 2025 @ 11:00 AM (EDT)
Quantum Spark Management Unleashed: Hands-On TechTalk for MSPs Managing SMB NetworksWed 03 Sep 2025 @ 11:00 AM (SGT)
Deep Dive APAC: Troubleshooting 101 for Quantum Security GatewaysThu 04 Sep 2025 @ 10:00 AM (CEST)
CheckMates Live BeLux: External Risk Management for DummiesWed 10 Sep 2025 @ 11:00 AM (EDT)
Quantum Spark Management Unleashed: Hands-On TechTalk for MSPs Managing SMB NetworksAbout CheckMates
Learn Check Point
Advanced Learning
YOU DESERVE THE BEST SECURITY