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.0
Published Oct 29, 2019
Version 1.0

Was this article helpful?

3 Comments

  • This returns "2" on both blade 1 and blade 2 of a test cluster running 13.1.1.4, where blade 2 is currently master.

    Here's the same in just awk:

    /usr/sbin/bladectl -g leds | /bin/awk '/slot.*Primary LED.*solid.*Green*/ {gsub(":","",$2);print $2}'
  • Running 13.1.1.4, I updated the original comment. The point is that the script shows the active blade, but does not check the blade we are currently on. Presumably this would need to parse /var/prompt/ps1 ?