OT Shell Script
Chris Knipe
cknipe at hybyte.com
Tue Jun 21 09:24:07 GMT 2005
May be a bit off topic, but I don't know any sh scripting lists that I'm subscribed to... :)
If I run the script from shell / console, it runs without a problem.... Running it via cron, I get: [: 6: unexpected operator
The script:
#!/bin/sh
HOSTNAME=`/usr/bin/uname -n`
SIZE=`/usr/bin/du /var/log/MYAPP/|/usr/bin/cut -c 1-7`
ROTATE="1024000"
if [ -e /tmp/.rotate ]; then
return 1
else
touch /tmp/.rotate
if [ $SIZE -ge $ROTATE ]; then
/bin/mkdir -p /usr/local/backup/var/logs
cd /usr/local/backup/var/logs
for X in `ls /var/log/MYAPP/`; do
rm -f $X.9.tgz
mv $X.8.tgz $X.9.tgz
mv $X.7.tgz $X.8.tgz
mv $X.6.tgz $X.7.tgz
mv $X.5.tgz $X.6.tgz
mv $X.4.tgz $X.5.tgz
mv $X.3.tgz $X.4.tgz
mv $X.2.tgz $X.3.tgz
mv $X.1.tgz $X.2.tgz
/usr/bin/tar -czf $X.1.tgz /var/log/MYAPP/$X > /dev/null
/bin/cat /dev/null > /var/log/MYAPP/$X
done
/bin/echo "/var/log/MYAPP Rotated on $HOSTNAME" | /usr/bin/mail -s "MYAPP Log Rotation" my at somwhere
fi
/bin/rm /tmp/.rotate
fi
No, unfortunately, I MUST script this, I cannot use logrotate / newsyslog / name your fav log rotation tool, as they all destroy active file handles on the log file. cating /dev/null to the log is a good way to clean the log, whilst allowing a MULTITUDE of applicating writing to the file, to keep their file handles in tact....
Anyone that can give me a indication of what is going haywire in the script?
Thank you kindly,
Chris.
More information about the freebsd-questions
mailing list