#!/bin/bash logrotate ..... # rotate out /data/file.txt perl -x $0 $@ > /data/file.txt 2>&1 mail -s "file.txt" me@example.com < /data/file.txt echo "Job done. Errors:" grep ERROR /data/file.txt exit ####### #!/usr/bin/perl # do whatever perl-friendly tasks -- process some files, do calculations, call CPAN modules for heavy lifting, whatever.