mirror of https://github.com/nirenjan/dotfiles.git
40 lines
857 B
Bash
Executable File
40 lines
857 B
Bash
Executable File
#!/bin/bash
|
|
# Monthly logging script
|
|
# Call mlog and it will update a log file
|
|
|
|
# Set the default mlog folder
|
|
[[ -z $MLOG_FOLDER ]] && MLOG_FOLDER="$HOME/mlog"
|
|
|
|
# Make sure that the folder exists
|
|
[[ ! -d $MLOG_FOLDER ]] && mkdir -pv $MLOG_FOLDER
|
|
|
|
# Make sure that we have a valid TMPDIR
|
|
[[ -z $TMPDIR ]] && TMPDIR='/tmp'
|
|
|
|
# Make sure that we have a valid EDITOR
|
|
[[ -z $EDITOR ]] && EDITOR=vim
|
|
|
|
MLOG_HDR=''
|
|
|
|
if [[ -x $HOME/bin/stardate ]]
|
|
then
|
|
[[ -z $MLOG_RANK ]] && MLOG_RANK='Chief Engineer'
|
|
|
|
MLOG_HDR="$MLOG_RANK's log, Stardate $($HOME/bin/stardate)\n"
|
|
fi
|
|
|
|
MLOG_HDR="$MLOG_HDR[$(date)]"
|
|
|
|
MLOG_FILE="$TMPDIR/mlog-tmp-$$"
|
|
|
|
$EDITOR $MLOG_FILE
|
|
|
|
[[ ! -s $MLOG_FILE ]] && exit 0
|
|
|
|
MLOG_LOG="$MLOG_FOLDER/$(date +%Y-%m)"
|
|
|
|
echo -e "$MLOG_HDR\n" >> $MLOG_LOG
|
|
cat $MLOG_FILE >> $MLOG_LOG
|
|
echo -e "\n----------------------------------------\n" >> $MLOG_LOG
|
|
|