IPMI tool function

By Paul Heinlein | Sep 28, 2015

In the vein of my post about an SSH login function I’ve added to my bash profile, here’s another profile function, this one for invoking ipmitool.

The ipmitool utility is really handy for out-of-band management of servers, but invoking it requires a lot of typing:

ipmitool -I lanplus -U username -H hostname -C 3 sol activate

In our environment,

Given that sort usage pattern, I coded it up:

function ipmicli {
  ipmitool \
  -H ${1:?"usage: $FUNCNAME host [cmd] [user]"}.ourdomain \
  -I lanplus -C 3 -U ${3:-ipmiuser} ${2:-sol activate}
}

Notes:

You can find full explanations for all the ${var:-word} syntax in the Parameter Expansion section of the bash man page.

Invoked without arguments, the function gives a short usage message:

[~]$ ipmicli
-bash: 1: usage: ipmicli host [cmd] [user]

Ordinary usage requires only an unqualified hostname:

# ipmitool -H hostname.ourdomain -I lanplus -C 3 -U ipmiuser sol activate
ipmicli hostname

When the commands passed to ipmitool contain whitespace, they must be quoted:

# ipmitool -H hostname.ourdomain -I lanplus -C 3 -U ipmiuser power status
ipmicli hostname "power status"