Add initial rc-power-management script
This commit is contained in:
parent
db2fbdebe4
commit
2f661126e7
2 changed files with 56 additions and 0 deletions
55
rc-power-management
Executable file
55
rc-power-management
Executable file
|
@ -0,0 +1,55 @@
|
|||
#!/bin/sh
|
||||
|
||||
###
|
||||
# Initialization.
|
||||
|
||||
for file in arp ipmitool; do
|
||||
if ! command -v $file > /dev/null; then
|
||||
echo "Could not find the 'arp' command. Exiting." >&2
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
###
|
||||
# Command-line argument handling.
|
||||
|
||||
if [ "$#" -le 2 ]; then
|
||||
echo "Usage: rc-power-management MACHINE_NAME IPMI_COMMAND" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
machine_name=$1
|
||||
ipmi_command=$(echo "$@" | cut --delimiter ' ' --fields 1 --complement )
|
||||
|
||||
###
|
||||
# Configuration handling.
|
||||
|
||||
if [ -f 'rc-power-management.conf' ]; then
|
||||
conf=rc-power-management.conf
|
||||
elif [ -f '/etc/rc-power-management.conf' ]; then
|
||||
conf=/etc/rc-power-management.conf
|
||||
fi
|
||||
|
||||
if [ "$conf" = "" ]; then
|
||||
echo "Could not find configuration file. Exiting." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
match=$(grep --max-count 1 "$NAME" < $conf)
|
||||
if [ "$match" = "" ]; then
|
||||
echo "Could not find machine $machine_name in $conf. Exiting." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
macaddr=$(echo "$match" | cut -d ',' -f 2)
|
||||
ipmi_user=$(echo "$match" | cut -d ',' -f 3)
|
||||
ipmi_password=$(echo "$match" | cut -d ',' -f 4)
|
||||
|
||||
###
|
||||
# Executing IPMI call.
|
||||
|
||||
ipaddr=$(arp -a | grep "$macaddr" | sed -n 's/^.*(\(.*\)) .*$/\1/p')
|
||||
echo "Executing '$ipmi_command' for $machine_name against $ipaddr..."
|
||||
|
||||
# shellcheck disable=SC2086
|
||||
ipmitool -I lanplus -H "$ipaddr" -U "$ipmi_user" -P "$ipmi_password" $ipmi_command
|
1
rc-power-management.example.conf
Normal file
1
rc-power-management.example.conf
Normal file
|
@ -0,0 +1 @@
|
|||
demo,2c:3a:fd:f6:13:0e,user,password
|
Loading…
Reference in a new issue