I am trying to delete sendmail messages from root my script which takes down the mail messages to be deleted into a file with there respected ids but even if run that from root it still not deleting it .All its says that permission denied cannot delete file ,even from the root
#!/usr/bin/ksh
WORKFILE="/tmp/check.mq"
MAILLIST="emailadress"
mailq|grep -B1 -i temporarily |grep -iv deferred |egrep -i 'jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec' |awk -F" " '{print $1}' |awk '{print substr($0,10,14)}' |tee -a $WORKFILE |awk '{print "*" $1}' |tee -a mail.mq
mailq|grep -B1 -i unknown|egrep -i 'jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec' |awk -F" " '{print $1}' |awk '{print substr($0,10,14)}' |tee -a $WORKFILE |awk '{print "*" $1}' |tee -a mail.mq
mailq|grep -B1 -i lookup |grep -iv deferred |egrep -i 'jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec' |awk -F" " '{print $1}' |awk '{print substr($0,10,14)}' |tee -a $WORKFILE |awk '{print "*" $1}' |tee -a mail.mq
cat mail.mq | while read file; do rm -rf /var/spool/mqueue/$file;done
find . -type f -name "mail.mq" |rm -rf mail.mq
i am using this code which takes down the id and than substrings the last 5 numbers of the id.
error i am getting is
rm: cannot lstat '/var/spool/mqueue/*11343' :Permission denied
I am getting permission denied on deleting those mails