#!/bin/sh
# report attempts to reboot via "Ctrl-Alt-Delete"
# version 0.7 (Last modified 23/06/2003)
# Author: Dean Wilson
#set -x #uncomment this for debug

######################################################

# external binaries used, you can hardcode them if your worried about paths.
LOGGER=/usr/bin/logger
TR=/usr/bin/tr
DATE=/bin/date
BASENAME=/usr/bin/basename


######################################################
# check that all the external dependcies are satisfied
function usage {
  for BINLOC in $LOGGER $TR $DATE $BASENAME
  do
    if [ ! -f "$BINLOC" ];then
      printf "Failed to find '$BINLOC' This script requires this to run\n"
      ERROR=1
      continue
    fi
    if [ ! -x "$BINLOC" ];then
      printf "'$BINLOC' does not seem to be executable, please fix\n"
      ERROR=1
      continue
    fi
  done

}
######################################################

# change these to alter how syslog sees the alert
FAC=user
LEVEL=crit

#Get the application name without the path
APP=$($BASENAME "$0")

#Log message
MSG="Ctrl-alt-delete was triggered and caught by $APP"

# External non-syslog logfile location
LOGFILE=/var/log/shutattempt

######################################################

#sanity checks, if we are called with '-c' validate external dependencies
if [ "$1" == "-c" ];then
  usage

  if [ -n "$ERROR" ];then
    RETCODE=1
  else
    RETCODE=0
  fi

  #never run after a check.
  exit $RETCODE
fi


#prep the external log file
$($DATE +'%b %d %T ' | $TR -d '\n' >>$LOGFILE)


#main work
$LOGGER -p ${FAC}.${LEVEL} -t $APP -s $MSG 2>>$LOGFILE
exit 0
