You are not logged in.
Pages: 1
I am a system administrator by trade, and I find it very hard to remember all of the configuration changes I make on a given day. Being able to remember this information can be very helpful. So I decided I wanted to keep a log of events, making troubleshooting easier and more productive.
I tried doing this in a notebook. But it quickly lost value as it was hard to search. One day I stumbled upon a script in the comment section of lifehacker.com, which I made a few modifications.
Enjoy!
#!/bin/bash
# By Joseph Kern <timetrap AT gmail DOT com>
ANSWER=$@
#Change this to the path of your log
LOG="$HOME/log/"
TODAY="`date +"%Y%m%d"`"
TIME="`date +"%T"`"
if [ "$1" = '-h' ]
then
echo "ql -- The QuickLogger -- Version 0.3"
echo
echo "OPTIONS:"
echo
echo " -a : List all logs."
echo " -s : Search for a term."
echo " <string> : Log it."
echo " ! <string> : Highlight in red"
echo " ? <string> : Highlight in yellow"
echo
echo "EXAMPLES:"
echo
echo ql "This is a log entry"
echo ql -a
echo ql -s SearchTerm
echo ql ! "Highlight this entry"
echo
echo "Depends on fortune (line 81)"
echo
exit
fi
# Options ---
# Highlight in red
if [ "$1" = '!' ]
then
ANSWER="\e[1;31m$@\e[0m"
fi
#Highlight in yellow
if [ "$1" = '?' ]
then
ANSWER="\e[1;32m$@\e[0m"
fi
if [ "$1" = '-a' ]
then
clear
cat $LOG*.log
exit
fi
if [ "$1" = '-s' ]
then
clear
cat $LOG*.log | grep $2
exit
fi
if [ "$1" = '' ]
then
clear
cat "$LOG$TODAY.log"
exit
fi
# Main ---
if [ -e "$LOG$TODAY.log" ]
then
echo -e "$TODAY $TIME -> $ANSWER" >> "$LOG$TODAY.log"
clear
cat "$LOG$TODAY.log"
else
echo >> "$LOG$TODAY.log"
# The following line may be commented out.
fortune >> "$LOG$TODAY.log"
echo >> "$LOG$TODAY.log"
echo -e "$TODAY $TIME -> $ANSWER" >> "$LOG$TODAY.log"
clear
cat "$LOG$TODAY.log"
fi
Usage
It will save one log file per day in a directory of your choosing. With a filename of YYYYMMDD.log
Installation
Copy and paste the above code into a file named 'ql' (or whatever)
chmod +x ql
./ql -h
It has one optional dependency: fortune (this can be commented out on line 81).
Example Output
poisoned coffee, n.:
Grounds for divorce.
20090105 07:46:20 -> This is a test entry
20090105 07:46:30 -> Another test entry.
20090105 07:46:41 -> And a final test entry.
Last edited by timetrap (2009-01-05 12:49:50)
Offline
Nice!
Now for a version that logs to PostgreSQL so it can be used on multiple machines with a central log
Last edited by fukawi2 (2009-01-05 21:34:21)
Are you familiar with our Forum Rules, and How To Ask Questions The Smart Way?
BlueHackers // fscanary // resticctl
Offline
Nice!
Now for a version that logs to PostgreSQL so it can be used on multiple machines with a central log
Hmmmmmmmm . . . .
Offline
I like the idea of using egp . . . But I am trying to keep it as simple as possible. (I don't write anything that I wouldn't put in an office email.) Your setup is more like a diary.
Offline
I like the idea of using egp...
You probably know this, but let's say it for those who don't. Aliases like this are useful to have in everyday operation:
alias gpgd='gpg --decrypt'
alias gpge='gpg -r "user <user@nodomain.tld>" -e '
...same commands could easily be included in the above script to have on the fly en/decryption.
There is also the alternative to use GPG CAST5 to password protect the files (gpg -c file, gpg -d file.gpg).
You need to install an RTFM interface.
Offline
I am a system administrator by trade, and I find it very hard to remember all of the configuration changes I make on a given day. Being able to remember this information can be very helpful. (...)
A script like this can indeed be useful if you need to log lot's of misc things, but if it's only about configuration changes, why not storing a config file under version control ? you get more advantages like that (directly link a specific version to a log message, ability to revert/merge/..., etc)
< Daenyth> and he works prolifically
4 8 15 16 23 42
Offline
timetrap wrote:I am a system administrator by trade, and I find it very hard to remember all of the configuration changes I make on a given day. Being able to remember this information can be very helpful. (...)
A script like this can indeed be useful if you need to log lot's of misc things, but if it's only about configuration changes, why not storing a config file under version control ? you get more advantages like that (directly link a specific version to a log message, ability to revert/merge/..., etc)
You assume that I managing linux/unix servers.
(I keep all of my personal configs in a git repo....)
Offline
Pages: 1