Date: Tue, 21 Jun 2005 11:23:46 +0200 From: "Chris Knipe" <cknipe@hybyte.com> To: <freebsd-questions@freebsd.org> Subject: OT Shell Script Message-ID: <000601c57642$edfce460$1e01a8c0@pc2xp>
next in thread | raw e-mail | index | archive | help
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=3D`/usr/bin/uname -n`
SIZE=3D`/usr/bin/du /var/log/MYAPP/|/usr/bin/cut -c 1-7`
ROTATE=3D"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@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....=20
Anyone that can give me a indication of what is going haywire in the =
script?
Thank you kindly,
Chris.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?000601c57642$edfce460$1e01a8c0>
