Here is a script to check if your Linux box is ready for the US DST 2007 Energy Act. Save it, chmod it, run it.
#!/bin/bash
status=0
glpackagecheck() {
rpm=$(rpm -q tzdata)
case $rpm in
tzdata-2005m*)
:
;;
tzdata-2006*)
:
;;
*)
echo "RPM tzdata-2005m-1 is not installed. You installed: $rpm"
status=$(($status+1))
;;
esac
}
glfilecheck() {
if [ ! -d /usr/share/zoneinfo/America/ ] ; then
echo "The /usr/share/zoneinfo/America directory does not exist."
status=$(($status+4))
fi
}
glfunctioncheck1() {
storedtz=$(echo $TZ)
export TZ="America/Adak"
date | grep 'HA.T' > /dev/null
if [ $? -gt 0 ] ; then
echo "Unable to switch timezone."
status=$(($status+8))
fi
export TZ="$storedtz"
}
glfunctioncheck2() {
zdump -v CST6CDT | grep 2007 | grep "Mar 11" > /dev/null
if [ $? -gt 0 ] ; then
echo "Wrong roll over date configured for CST6CDT."
status=$(($status+16))
fi
}
glpackagecheck
glfilecheck
glfunctioncheck1
glfunctioncheck2
if [ "$status" -gt 0 ] ; then
echo "Not all tests ended with success, the status is: $status."
else
echo "All test successful, you are prepared for the US DST change."
fi
Here is a script to rotate any logfile. Optionally a filesize can be given. It contains some extra features that are not (yet) in the logrotate facility.
I am not sure it works, but hey, you can tweak it! ;-)
#!/bin/bash
defaultconfig() {
PATH=/usr/bin:/usr/local/bin
number=9
}
usage() {
echo "Usage: $0 [-h|--help] [-c [VALUE]] [-s VALUE] [-n VALUE] -f FILE"
echo ""
echo " -h, --help"
echo " Display this screen."
echo " -c"
echo " Use gzip to compress file."
echo " -s VALUE"
echo " rotate the file is the size equals VALUE. Size in bytes."
echo " If no size is specified, the file is rotated without"
echo " checking its size."
echo " -n VALUE"
echo " rotate VALUE number of file. Default is set to 9"
echo " -d DIRECTORY"
echo " Move the rotated files to DIRECTORY."
echo " -f FILE"
echo " FILE is the file to be rotated. This is an argument, not"
echo " an option."
echo " -p COMMAND"
echo " execute COMMAND before (pre) rotating."
echo " -P COMMAND"
echo " execute COMMAND after (post) rotating."
echo ""
exit 1
}
readargs() {
while [ "$#" -gt 0 ] ; do
case "$1" in
-c)
compress="yes" && extension=".gz"
shift
;;
-s)
if [ "$2" ] ; then
size="$2"
shift ; shift
else
echo "No size specified."
echo ""
usage
fi
;;
-n)
if [ "$2" ] ; then
number="$2"
shift ; shift
else
echo "Number of files to rotate not specified."
echo ""
usage
fi
;;
-f)
if [ -f "$2" ] ; then
file="$2"
shift ; shift
else
echo "No such file: $2."
echo ""
usage
fi
;;
-d)
if [ -d "$2" ] ; then
directory="$2"
shift ; shift
else
echo "No such directory: $2."
echo ""
usage
fi
;;
-p)
if [ "$2" ] ; then
command=`echo "$2" | awk '{print $1}'`
if [ -x "$command" ] ; then
precommand="$2"
shift ; shift
else
echo "Command $precommand cannot be executed"
echo ""
usage
fi
else
echo "No command specified"
echo ""
usage
fi
;;
-P)
if [ "$2" ] ; then
command=`echo "$2" | awk '{print $1}'`
if [ -x "$command" ] ; then
postcommand="$2"
shift ; shift
else
echo "Command $postcommand cannot be executed"
echo ""
usage
fi
fi
;;
*)
echo "Unknown option $1"
echo "You must specify at lease a file with the \"-f\" argument."
echo ""
usage
;;
esac
done
}
precommand() {
if [ "$precommand" ] ; then
$precommand
if [ "$?" -gt 0 ] ; then
echo "Command $precommand failed, aborting."
echo
usage
fi
fi
}
postcommand() {
if [ "$postcommand" ] ; then
$postcommand
if [ "$?" -gt 0 ] ; then
echo "Command $postcommand failed, retrying."
sleep 3
$postcommand
if [ "$?" -gt 0 ] ; then
echo "Command $postcommand failed, aborting."
echo
usage
fi
fi
fi
}
rotatefiles() {
if [ -f "$file" ] ; then
while [ "$number" -ge 1 ] ; do
if [ -f "$directory$file.$number$extension" ] ; then
let numberplusone="$number + 1"
mv "$directory$file.$number$extension" "$directory$file.$numberplusone$extension"
fi
let number="$number - 1"
done
else
echo "No file to rotate."
echo ""
usage
fi
}
firstmove() {
precommand
cp "$file" "$directory$file.1"
cp /dev/null "$file"
chmod 644 "$file"
postcommand
if [ "$compress" ] ; then
gzip "$directory$file.1"
fi
}
startrotator() {
let number="$number -1" && rotatefiles
firstmove
}
checkrunning() {
mode="$1"
instances=`ps -ef | grep "$0" | grep -v "$$"`
numberofinstances=` echo "$instances" | wc -l`
if [ "$numberofinstances" -gt 1 ] ; then
if [ "$mode" = "silent" ] ; then
exit 1
else
echo "$0 is already running. Stopping this instance."
echo "instances:"
echo "---"
echo "$instances"
echo "---"
echo '$0'": $0"
echo '$$'": $$"
exit 1
fi
fi
}
checkrunning silent || ( sleep 60 ; checkrunning )
defaultconfig
readargs "$@"
if [ -f "$file" ] ; then
if [ "$size" ] ; then
filesize=`ls -l "$file" | awk '{print $5}'`
if [ "$filesize" -gt "$size" ] ; then
startrotator
fi
else
startrotator
fi
else
echo "You did not specify a file."
echo ""
usage
fi