CodeShare
Have some code. Share some code.
cancel
Showing results for 
Search instead for 
Did you mean: 
Custom Alert Banner
Richard_Shuford
Legacy Employee
Legacy Employee

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
Comments
TimRiker
Cirrostratus
Cirrostratus

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}'
Richard_Shuford
Legacy Employee
Legacy Employee

What BIG-IP release is this test cluster running?

TimRiker
Cirrostratus
Cirrostratus

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 ?

Version history
Last update:
‎29-Oct-2019 13:47
Updated by:
Contributors