Forum Discussion
tmsh command to search contents of all Irules for a string
- Apr 30, 2021
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 🙂
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 🙂
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com