0

I need to write a log file that will be contain all mail contents of the particular mail id from the mail queue.

I have written the below code that will be shown the all mailID.

mailq | tail -n +2 | awk 'BEGIN { RS = "" } / root@'+`hostname`+'$/ { print $1 }'

example: my hostname as test.com the above query will be shows the all mail queue ID of the root@test.com

Output: like that

295E36A10B7
270986A1407
26F296A1460
9099D6A02F8

but i will try the following query for showing the content of the mailqueue ID. That's not working.

for i in mailq | tail -n +2 | awk 'BEGIN { RS = "" } / root@'+`hostname`+'$/ { print $1 }' ; do postcat -q $i >> maillog.log; postsuper -d $i; done ; 

that not working. could you please give an idea for showing the all mail contents.?

0

Finally i have tried the below solution. That's working fine.

array=($(mailq | tail -n +2 | awk 'BEGIN { RS = "" } / root@'+`hostname`+'$/ { print $1 }'));
for i in ${array[@]}; 
do 
postcat -q $i >> maillog.log;
 postsuper -d $i; 
done

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.