is this script running on the primary blade?
Problem this snippet solves:
Often, for example in an external monitor script, it is desirable for the script to execute only on the primary blade of a VIPRION cluster. Traditionally, in BIG-IP, a script has executed "tmsh show sys cluster" and then parsed the output (with "grep" and "awk") to derive a value which indicates whether it is running on the primary blade. However, there is another way to find out, using a different command ("bladectl") which runs more quickly and with less overhead than "tmsh".
How to use this snippet:
Embed this one-liner into your script, with appropriate surrounding logic. If running on the primary, it returns '1'. If running on a secondary blade, it returns '0'.
Code :
/usr/sbin/bladectl -g leds | /bin/sed -n 'y/:/ /;/Primary LED is[ ]*solid[ ]*Green/p' | /bin/awk -F " " '{ print $2}'
Tested this on version:
13.0Published Oct 29, 2019
Version 1.0