Automate Hotline news file rotations

Jun 17, '02 09:33:54PM

Contributed by: THEM

One of the most dreaded things when running a Hotline server is cleaning the news. I wrote the following script to automate that task. Most of it is set up as variables that can easily be changed for your set up. I have only tested it with the hxd server, however it should also work with a plain vanilla Hotline server. For adding it to cron, I suggest grabbing CronniX for easy editing.

Read the rest of the article for the script...

#! /bin/sh

###########################################
# Hotline News Cleaner v1 by James Huston #
# Add this program to the cron system to #
# auto clean your news file at specified #
# times. #
###########################################

# CHANGE THESE VARIABLES FOR USE ON YOUR SYSTEM #
hxdpath=/Users/hxd/ #path to the hxd server root
newssize=30000 #size to act upon in bytes
posts=3 #number of posts you want to keep
newsdelim="_________________________________________________" # the news delimiter
tdate=`date +%x | tr "/" "-"` #date formate for arcived files

cd "$hxdpath" #change to server folder
cursize=`ls -l news | tr -s " " "\t" | cut -f 5` #get news file size in bytes
if [ $cursize -gt $newssize ] #test the size
then
cp news news$tdate.txt #backup current news file
#run an awk program passing the number of posts to keep
#print each line from the top
#if the line is the delimiter increase counter by one
#if the counter equals the keep value exit
awk -v keep=$posts -v delmi=$newsdelim '{ print $0;
if ($0 == delim) counter = counter + 1;
if (counter == keep) exit }' news$tdate.txt >> news.new
gzip -9 news$tdate.txt #archive the old news file
mv news.new news #mv the new news file replacing the old
fi
Save the script, make it executable (chmod 755 script_name), and make sure it's stored somewhere on your path.

Comments (2)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20020617213354755