#!/usr/bin/bash

ACTION=${1}
CAUSE=${2}

if [[ ${#CAUSE} -gt 64 ]]; then
    echo "Maximum length of cause string is 64 symbols"
    exit 1
fi

printf "${CAUSE}\n" > /tmp/.shutdown

case "${ACTION}" in
"shutdown")
    shutdown -h now
;;
"reboot")
    reboot
;;

esac