IPMI tool function

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,

  • the hostname changes all the time, so it’s a required parameter,
  • the command is usually sol activate, which gives access to a serial-over-LAN console, but that’s not always the case, so it’s an optional parameter,
  • the username (which is of course super-secret) rarely changes, but it might, so it’s also optional.

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:

  • The first positional parameter, the unqualified hostname, is required. If not present, the function will return an error, printing a short usage message.
  • The second positional parameter is optional and defaults to sol activate.
  • The third parameter is also optional and defaults to ipmiuser (or whatever our super-secret IPMI account is actaully named).

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"

Howto  Linux