One use for truncation is to collect daily reports from mailstats. Consider the
following simple shell script:
#!/bin/sh
ST=/etc/mail/statistics
MS=/usr/etc/mailstats
if [ -s $ST -a -f $MS ]; then
$MS | mail -s "Daily mail stats" postmaster
cp /dev/null $ST
fi
exit 0
When run, this script checks to see whether a nonempty statistics file and the mailstats
program bothexist. If they do, mailstats is run, printing the statistics, which are
then mailed to postmaster. The statistics file is then truncated to a size of zero. Such
a script could be run once per night using the cron(8) facility witha crontab(5) entry
like this:
0 0 * * * sh /usr/ucb/mailstats.script >/dev/null 2>&1
Here, mailstats.script is the name given to the earlier shell script, and the 0 0
causes that script to be executed once per day at midnight.
Moving and renaming the statistics file allows you to automatically collect daily copies
of that file. Consider the following variation on the previous shell script:
#!/bin/sh
BASE=/etc/mail
ST=statistics
MS=${BASE}/stats_arch
if [ -d $BASE ]; then
cd $BASE
if [ -s $ST -a -d $MS ]; then
mailstats | mail -s "Daily mail stats" postmaster
test -f ${MS}/${ST}.5 && mv ${MS}/${ST}.5 ${MS}/${ST}.6
test -f ${MS}/${ST}.4 && mv ${MS}/${ST}.4 ${MS}/${ST}.5
test -f ${MS}/${ST}.3 && mv ${MS}/${ST}.3 ${MS}/${ST}.
Pages:
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663