Satya's blog - Pidgin logs archiver

May 15 2009 19:50 Pidgin logs archiver

I wrote a little script to archive my pidgin logs in a sepaarte directory. 4 lines, but took 45 minutes to write. Use at own risk. This should be under the Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License. But should this script do anything, or not do something, don't hold me responsible. In fact, don't use this at all.

YEAR=2008
DEST=/home/whatever/chatlogs/$YEAR

# Copy the directory structure.
find . -type d -exec mkdir -p "$DEST/{}" \;

# Copy the files starting with the year.
find . -name $YEAR*.txt -exec mv "{}" $DEST/{} \;

# For the rmdirs, we could use -exec command + instead of -exec command ; but we don't because
# this script simply doesn't run very often.

# Remove any extra directories we made, go depth-first
find $DEST -depth -type d -exec rmdir --ignore-fail-on-non-empty {} \;

# Remove any empty directories in case we took away all the files, go depth-first
find . -depth -type d -exec rmdir --ignore-fail-on-non-empty {} \;

It should not be run from the .purple/logs directory, or wherever. After that's done, you can not go tar cz (create, compress with gzip) the directory.

Tag: geeky shell howto