cd /etc/systemd/system
if [[ ! rebootsh.service ]]; then
cat > rebootsh.service << EOF
[Unit]
Description=Notify sys admin when the server gets rebooted
After=network.target
After=postfix.service
[Service]
Type=simple
ExecStart=/root/bin/reboot.sh
TimeoutStartSec=0
RemainAfterExit=no
[Install]
WantedBy=rescue.target
WantedBy=multi-user.target
WantedBy=graphical.target
EOF
echo "Added the rebootsh service"
chmod 444 rebootsh.service
systemctl enable rebootsh.service
else
echo "Rebootsh.service already in place"
fi
cd /root/bin
if [[ ! -f reboot.sh ]]; then
cat > reboot.sh << EOF
#!/bin/bash
#
# Send an e-mail whenever the system starts.
#
DATE=$(/bin/date +'%d%b%y')
TIME=$(/bin/date +'%H:%M%:S')
HOST=$(/bin/hostname -s)
SUBJ="${HOST} has been booted on ${DATE} at ${TIME}"
BODY=$(/bin/mktemp)
echo "" > ${BODY}
echo "The last five logins were:" >> ${BODY}
/usr/bin/who /var/log/wmtp | /usr/bin/tail -5 >> ${BODY}
#
/bin/mailx -s "${SUBJ}" ${NOTIFY} < ${BODY}
/bin/rm ${BODY}