Installing & Using "loggit"

Installing loggit

Following is a my loggit script. If you want to set it up as I have, perform the following steps.

  1. Copy and paste the script into a text file on your computer.
  2. Put the loggit file it in /usr/local/bin
  3. Execute:  chmod 755 /usr/local/bin/loggit
  4. Execute:  chown root:root /usr/local/bin/loggit   You can set the owner and group to what is appropriate for your distribution.
  5. Verifiy that the logfile is going to live in /var/log.  If you want to put the logfile somewhere else, make sure the LOG variable reflects your choice.
  6. Execute:  touch /var/log/loggit.log
  7. Execute:  chmod 666 /var/log/loggit.log
  8. Execute:  chown root:root /var/log/loggit.lo

I put the logfile (loggit.log)into the system log directory, /var/log, so it will get backed up with other system logfiles.  If you give the logfile 666 permissions, and make root the owner and group, then anyone can read and write to the log.

Using loggit

To use the script, type loggit at a command prompt,  You will see a message on the next line:  "Press <CTRL-D> to end input" and the curor is sitting below the "P".  Simply start typing whatever you want to save in the logfile.  When you are done, hold the ontrol key down and press the "D" key.  You will see the command pompt come back.

When you look at the logfile, you will see an entry similar to the following:

Mon Jun 17 19:37:44 EDT 2019 - SYSTEM - user

testing loggit
========================================

The script timestamps the entry, records the system name and the effective user ID.  Next comew whatever you entered and then a line of dashes provide the delimiter at the end of every record.

The loggit Script

#!/bin/sh
# $Id: $
#
#######################################################
#
# Filename: loggit
# Author: Kay-Marie Slaughter
# Date: Friday, May 16, 2014, 20:16:28 EDT
#
# Purpose: Create a file of changes or other
# information that should be documented
# on a Unix/Linux server.
#
# Modified: 10/5/2014 - modified for Raspberry Pi.
# You should run this as "sudo loggit"
# the first time to create the log
# directory and loggit.log
#
# Notes: Adapted from "logger" script found in
# Unix Administration Guide for System V,
# by Rebecca Thomas and Rik Farrow, (c) 1989.
#
# You may have to create file as root,
# if you put it on /var/log.
#
#######################################################
#
# set variables
DATE=`date` # timestamp for entry
HOST="$( echo `hostname` | tr [a-z] [A-Z])" # read hostname & capitalize
USER=`who am i | cut -c1-8` # login name of user
LOG='/var/log/loggit.log' # where does the log live?

# if the log doesn't exist, create it.
#if ( ! ${LOG} ) then
# touch ${LOG}
# chmod 666 ${LOG}
# chown root:root ${LOG}
# echo "Logfile created.\n"
#fi
#
# this is where the entry is created
echo "Press <CTRL-D> to end input."
#
# after the entry is complete, send all to logfile.
echo -e "${DATE} - ${HOST} - ${USER}\n" >> ${LOG}
cat >> ${LOG}
echo -e "========================================\n" >> ${LOG}
#
# end of script
#