Server Change Log Script

Server Change Log script

I've been a UNIX sysadm for several years now, and I have come to appreciate change logs on servers.

I wrote a script which I currently deploy to servers with puppet.

# ChangeLog script v. 0.4 -  Ashren
 
chlogpath="/ChangeLog"
 
if [[ -z "${SUDO_USER}" ]] && [[ $UID != 0 ]]; then
    echo "Please use sudo or root."
    exit 1
fi
 
if [[ ! -a $chlogpath ]]; then
    echo -e "\nChangeLog for ${HOSTNAME}" >> $chlogpath
fi
 
if [[ -z "${SUDO_USER}" ]]; then
    read -p "Please enter initials: " init
    sed -i '1i '"$(date)"' '"$init"'\n\n\n' $chlogpath
    vi +3 $chlogpath
    exit 0
else
    sed -i '1i '"$(date)"' '"$SUDO_USER"'\n\n\n' $chlogpath
    vi +3 $chlogpath
fi