From time to time, I find some settings for vi on remote systems that really kind of freak me out. The one I found recently was ‘incsearch’ so I decided to use this opportunity to note down the settings I use on a daily basis. Hope you find some of these useful.
syntax on
set hlsearch
set incsearch
set ruler
set showmatch
syntax on is pretty obvious. If you’re writing code, it’s pretty smart about highlighting the code so it’s easier to read. It can be odd at first but I find it really useful and after a while, it becomes second nature.
set hlsearch highlights your search terms so they’re easy to see. I like this option a lot. not everyone does.
set incsearch searches as you type. It’s new to me so I’m still getting used to it but I think I can already see some uses for it.
set ruler shows you where your cursor is at all times. I like this option a lot if only to tell me what line number I’m on. set number will also do this but I also find it irritating because it also interferes with my copy/paste habits.
set showmatch is really useful if you’re a coder. If you’ve got somewhat complicated conditional statements or loops, this feature will show you where brackets match so you can find missing brackets and close the proper blocks.
Hope these help. I’ll update these as I find more.
A while back, I was asked to come up with a logrotation script.
This script would rotate all logs into a tarball and move it somewhere for archival purposes.
The problem was that I couldn’t just rotate today’s logs because it would be incomplete. I had to intelligently find a way to rotate the previous days logs (which would be complete) and then tar them up.
It turns out that you can do this with the “date” command in linux.
YESTERDAY=$(date -d "yesterday" '+%Y-%m-%d')
echo $YESTERDAY
This little snippet came in very handy and so I thought would share it.
The whole script is very small actually. Here it is. All you want to do is direct the output to a log file so you can review it later if need be. It’s chatty but you want chatty when you’re backing up and deleting log files.
#!/bin/bash
if [ $# -lt 3 ]; then
echo "USAGE: backup_logs.sh ORIGINAL FILE-PREFIX- DESTINATION"
exit
fi
# get command line variables
FILE=$2
ORIG=$1
DEST=$3
# get current time for log files.
NOW=$(date)
# get yesterdays date
YESTERDAY=$(date -d "yesterday" '+%Y-%m-%d')
# beginning entry in the log file
echo "$NOW Backing up $FILE from $ORIG for $YESTERDAY to $DEST/$FILE-$YESTERDAY.tgz"
echo "$NOW Command is /bin/tar -zcvf $DEST/$FILE$YESTERDAY.tgz $ORIG/$FILE$YESTERDAY*"
/bin/tar -zcvf $DEST/$FILE$YESTERDAY.tgz $ORIG/$FILE$YESTERDAY*
echo $NOW Done backing up logfiles to $DEST/$FILE-$YESTERDAY.tgz
echo "$NOW removing files that were backed up."
/bin/rm -vf $ORIG/$FILE$YESTERDAY*
echo "$NOW done removing backuped up files."