boot-notify

Just put together a quick bash script I call to email me when my pogo server comes online.

#!/bin/bash
###
### ff0000scripts
### notify-boot
### 20150419
###

###set defaults

#set host #$(hostname) for computer name
#HOST=myComputerID
HOST=$(hostname)

#set user to mail to.... or email address
#MAILTO=me
#MAILTO=$(id -un)
#generated email address user@machine: MAILTO="$(id -un)@$(hostname -f)"
MAILTO=$(id -un)

#input options/arguments
while getopts :h:m:c:s: option; do
  case "${option}" in
    h)
      HOST=${OPTARG}
      ;;
    m)
      MAILTO=${OPTARG}
      ;;
    c)
      CONTENTS=${OPTARG}
      ;;
    s)
      SUBJECT=${OPTARG}
      ;;
    \?)
      echo "Invalid option: -${OPTARG}" >&2
      echo " -h: hostname"
      echo " -m: mailto"
      echo " -s: subject"
      echo " -c: message contents"
      echo " -?: help"
      exit 1
      ;;
    :)
      echo "Option -${OPTARG} requires an argument." >&2
      exit 1
      ;;
  esac
done

#set subject if not specified by -s
if [ -z "${SUBJECT}" ];
then
  SUBJECT="${HOST} rebooted";
fi

#set message contents if not specified by -c
if [ -z "${CONTENTS}" ];
then
  CONTENTS="${HOST} rebooted";
fi

echo "${CONTENTS}" | mail -s "${SUBJECT}" ${MAILTO}

2015-04-19notify-boot


Posted

in

,

by

Comments

Leave a Reply