Forum Discussion
How to add iRules using CLI
I've done this same task with this script I've made. I add an iRule preserving all existing ones on the Virtual Server.
#!/bin/sh
# f5-irule-add - add iRule to a virtual server, preserving existing iRule configuration
# Gian Henriques, 30/06/2021
# hot to use: ./script.sh new_irule my_vs
virtual=$2
irule_add=$1
#Capture existing iRule configuration
tmsh list ltm virtual ${virtual} one-line | grep -q " rules { "
if [ $? -eq 1 ]; then
echo "$0: ${virtual} currently contains no rules; adding new rule"
irule_current=""
else
irule_current=`tmsh list ltm virtual ${virtual} one-line | sed -e 's/.* rules { //' -e 's/ }.*//'`
# Check if rule already exists
exists=0
for rule in ${irule_current}
do
if [ ${rule} == ${irule_add} ]; then
exists=1
fi
done
if [ ${exists} -eq 1 ]; then
echo "$0: ${irule_add} already exists in virtual ${virtual}" >&2
#exit 2
else
# Modify iRule list
command="tmsh modify ltm virtual ${virtual} rules { ${irule_current} ${irule_add} }"
echo ${command}
exec ${command}
status=$?
if [ ${status} -ne 0 ]; then
echo "tmsh returned error status ${status}" >&2
exit ${status}
fi
fi
fi
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