30-Apr-2021 06:21
I need to query our F5 Irules for a certain string. Is there an easy way to query all irules across partitions?
Solved! Go to Solution.
30-Apr-2021
07:26
- last edited on
04-Jun-2023
20:55
by
JimmyPackets
Well a script would always be helpful in these cases. There is no one-line command for Irule, so its not doable through command. You can use this below script.
Create a bash script with below contents.
#!/bin/bash
searchword=$1
RULES="$(tmsh -q -c "cd /; list ltm rule recursive" | grep "ltm rule" | awk '{print $3}')"
if [ "$RULES" != "" ]; then
for eachrule in ${RULES}
do
result="$(tmsh -q -c "cd /; list ltm rule $eachrule" | grep $searchword)"
if [ "$result" != "" ]; then
echo "$eachrule"
fi
done
fi
Then execute it below format, where Version is your search string.
bash /var/tmp/find-string-rule.sh Version
[admin@Lab:Active:Standalone] ~ # bash /var/tmp/find-string-rule.sh Version
Common/App1-pool_selection-irule
Common/DDOS-irule
dummy/test-rule
As you could see, I got 3 results, 2 rules from Common partition & 1 rule from my dummy partition.
Hope this helps 🙂
30-Apr-2021 07:08
Not sure if there's an easy TMSH command for it, but can you run linux commands? I think this one should be pretty close to what you need:
grep -rnw '/config/partitions/' -e 'certainstring'
This searches through all files in the partitions' config for the "certainstring", though if there are a lot of files in the partitions, you may need to expand the filter a bit more.
Based on https://stackoverflow.com/questions/16956810/how-do-i-find-all-files-containing-specific-text-on-linux in case you want to see some more options.
30-Apr-2021
07:26
- last edited on
04-Jun-2023
20:55
by
JimmyPackets
Well a script would always be helpful in these cases. There is no one-line command for Irule, so its not doable through command. You can use this below script.
Create a bash script with below contents.
#!/bin/bash
searchword=$1
RULES="$(tmsh -q -c "cd /; list ltm rule recursive" | grep "ltm rule" | awk '{print $3}')"
if [ "$RULES" != "" ]; then
for eachrule in ${RULES}
do
result="$(tmsh -q -c "cd /; list ltm rule $eachrule" | grep $searchword)"
if [ "$result" != "" ]; then
echo "$eachrule"
fi
done
fi
Then execute it below format, where Version is your search string.
bash /var/tmp/find-string-rule.sh Version
[admin@Lab:Active:Standalone] ~ # bash /var/tmp/find-string-rule.sh Version
Common/App1-pool_selection-irule
Common/DDOS-irule
dummy/test-rule
As you could see, I got 3 results, 2 rules from Common partition & 1 rule from my dummy partition.
Hope this helps 🙂
02-May-2021 02:31
Both of these solutions work great! Thank you so much !
03-May-2021
04:02
- last edited on
24-Mar-2022
01:18
by
li-migration
Glad we could be of help, please feel free to mark either of the answers as solution provided, so the thread can be closed & it would help others as well.