- Products
- Learn
- Local User Groups
- Partners
- More
Call For Papers
Your Expertise, Our Stage
Ink Dragon: A Major Nation-State Campaign
March 11th @ 5pm CET / 12pm EDT
AI Security Masters E5:
Powering Prevention: The AI Driving Check Point’s ThreatCloud
The Great Exposure Reset
AI Security Masters E4:
Introducing Cyata, Securing the Agentic AI Era
CheckMates Go:
CheckMates Fest
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 |
|---|---|
| 8 | |
| 7 | |
| 6 | |
| 5 | |
| 5 | |
| 5 | |
| 4 | |
| 4 | |
| 4 | |
| 4 |
Thu 12 Mar 2026 @ 05:00 PM (CET)
AI Security Masters Session 5: Powering Prevention: The AI Driving Check Point’s ThreatCloudTue 17 Mar 2026 @ 03:00 PM (CET)
From SASE to Hybrid Mesh: Securing Enterprise AI at Scale - EMEAThu 12 Mar 2026 @ 05:00 PM (CET)
AI Security Masters Session 5: Powering Prevention: The AI Driving Check Point’s ThreatCloudTue 17 Mar 2026 @ 03:00 PM (CET)
From SASE to Hybrid Mesh: Securing Enterprise AI at Scale - EMEATue 17 Mar 2026 @ 02:00 PM (EDT)
From SASE to Hybrid Mesh: Securing Enterprise AI at Scale - AMERWed 18 Mar 2026 @ 10:00 AM (CET)
The Cloud Architects Series: An introduction to Check Point Hybrid Mesh in 2026 - In Seven LanguagesTue 24 Mar 2026 @ 06:00 PM (COT)
San Pedro Sula: Spark Firewall y AI-Powered Security ManagementThu 26 Mar 2026 @ 06:00 PM (COT)
Tegucigalpa: Spark Firewall y AI-Powered Security ManagementAbout CheckMates
Learn Check Point
Advanced Learning
YOU DESERVE THE BEST SECURITY