shirtcollar
Technical User
We put together the following script to delete unwanted system generated messages from root's mailbox.
We also need to delete messages that have no subject. Can anyone help us to modify our "for SUB in "
statement to include e-mails without subjects? Thank-you in advance.
#! /usr/bin/sh
# This script edits the roots (users) /var/mail/root file
using mailx to delete
# selected (by subject) email. The SUB variable is used to
id the subjects
# selected for deletion.
# cron entry is 0 18-23 * * 1-5 $HOME/junkmail
#=========================================================#
# Check to see if a user has their email open, exit
if true
#=======================================================#
if test -f /tmp/mbox.$LOGNAME
then
exit
fi
#=======================================================#
# list key words subjects of emails targeted for
deleation
# subjects list can be wrapped by using the
backslash (\)
# which continues the list to the next line
#=======================================================#
for SUB in at cron Undeliverable: FAILURE:
do
#=======================================================#
# For each subject listed build a list of their
line numbers
# as listed in the email.
#=======================================================#
for i in $SUB
do
#=======================================================#
# get list of subjects in the current mbox, less
the header info
# select the subject and secure its position number
in the file
#=======================================================#
NUM=`echo z+|mailx -H|cut -c1-7,50-|grep $i|cut -c3-
6|sed 's/U/ /' |sed 's/N/ /'`
#========================================================#
# if there is an entry for a subject then delete it
from the mail
# box. This opens and deletes all email with the
selected subject
# then closes the mbox back up. If none are
selected skip to the
# next subject on the list
#=======================================================#
if [ X"$NUM" != X ]
then
echo d$NUM | mailx
fi
done
done
exit
We also need to delete messages that have no subject. Can anyone help us to modify our "for SUB in "
statement to include e-mails without subjects? Thank-you in advance.
#! /usr/bin/sh
# This script edits the roots (users) /var/mail/root file
using mailx to delete
# selected (by subject) email. The SUB variable is used to
id the subjects
# selected for deletion.
# cron entry is 0 18-23 * * 1-5 $HOME/junkmail
#=========================================================#
# Check to see if a user has their email open, exit
if true
#=======================================================#
if test -f /tmp/mbox.$LOGNAME
then
exit
fi
#=======================================================#
# list key words subjects of emails targeted for
deleation
# subjects list can be wrapped by using the
backslash (\)
# which continues the list to the next line
#=======================================================#
for SUB in at cron Undeliverable: FAILURE:
do
#=======================================================#
# For each subject listed build a list of their
line numbers
# as listed in the email.
#=======================================================#
for i in $SUB
do
#=======================================================#
# get list of subjects in the current mbox, less
the header info
# select the subject and secure its position number
in the file
#=======================================================#
NUM=`echo z+|mailx -H|cut -c1-7,50-|grep $i|cut -c3-
6|sed 's/U/ /' |sed 's/N/ /'`
#========================================================#
# if there is an entry for a subject then delete it
from the mail
# box. This opens and deletes all email with the
selected subject
# then closes the mbox back up. If none are
selected skip to the
# next subject on the list
#=======================================================#
if [ X"$NUM" != X ]
then
echo d$NUM | mailx
fi
done
done
exit