Skip to content

Instantly share code, notes, and snippets.

@rkumar
Created November 4, 2009 16:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rkumar/226153 to your computer and use it in GitHub Desktop.
Save rkumar/226153 to your computer and use it in GitHub Desktop.
shell script to add data to bottom of file in consistent format
#!/bin/bash
#*******************************************************#
# Log things into a file in one consistent format #
# I needed to change IFS else newlines were getting hogged#
# appends to files (use genericdiary.sh to prepend to files)
# Arunachalesha #
# $Id$ #
#*******************************************************#
#TMPFILE=/usr/tmp/junk.$$
#trap 'rm -f $TMPFILE; exit 0' 1 2 15
if [ $# -eq 0 ]
then
echo "I got no filename"
exit 1
fi
logfile=$1
today=$(date +"Date: %Y-%m-%d %H:%M")
OLDIFS=$IFS
IFS="~"
echo Try to stick to maruku or markdown format
echo End with Ctrl-D, Ctrl-C to abort
echo " "
echo -n "Enter title: "
read title
echo "Enter text, C-d to end:"
text=`rlwrap cat`
#cat >> $logfile
echo "" >> $logfile
title="Subject: $title"
echo "$title" >> $logfile
echo $title | sed 's/./-/g' >> $logfile
echo $today >> $logfile
echo "" >> $logfile
echo $text >> $logfile
echo "" >> $logfile
echo '* * * * * * * *' >> $logfile
echo Done
echo "++++++"
IFS=$OLDIFS
tail $logfile
echo Output went to $logfile
#echo Use log2html.sh to view log in browser.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment