I am running a shell script on the mailq to create a list of files to delete, but i cannot delete them with shell script due to permissions (when i use root permissions the script works but i cannot always give root password for root permissions to a user). i would like to send the output list of files to perl in order to delete them and that Perl program has root priveleges.
the shell script is:
#!/usr/bin/ksh
WORKFILE="/tmp/check.mq"
MAILLIST="yagyavalkbhatt@yahoo.com"
mailq|grep -B1 -i temporarily |grep -iv deferred |egrep -i 'jan|feb|mar|apr|may|june|jul|aug|sept|oct|nov|dec' |awk -F" " '{print $1}' |awk '{print substr($0,10,14)}'|tee $WORKFILE |awk '{print "*" $1}'|tee mail.mq
mailq|grep -B1 -i unknown |egrep -i 'jan|feb|mar|apr|may|june|jul|aug|sept|oct|nov|dec' |awk -F" " '{print $1}' |awk '{print substr($0,10,14)}'|tee $WORKFILE |awk '{print "*" $1}'|tee mail.mq
mailq|grep -B1 -i lookup |grep -iv deferred |egrep -i 'jan|feb|mar|apr|may|june|jul|aug|sept|oct|nov|dec' |awk -F" " '{print $1}' |awk '{print substr($0,10,14)}'|tee $WORKFILE |awk '{print "*" $1}'|tee mail.mq
cat mail.mq | while read file; do rm /var/spool/mqueue/$file;done
find . -type f -name "mail.mq" |rm -rf mail.mq
which creates output like:
*##### where ##### is a unique 5 numbers to identify files in the mailq.
i want to know how i can delete these files with root priveleges from any user.
Redirect STDERR to STDOUT and read it together.
Example: