I am not sure what exactly is the reason, but the o/p of
postsuper -d seems to be not piped to
tail command. Try this,
Redirect the o/p of
postsuper -d to some tempfile. Get the count of messages from the
tempfile.
Code:
mailq | grep -v "^[^0-9A-Z]+" | grep MAILER-DAEMON | awk '{print $1}' | postsuper -d - >tempfile
no_of_msgs=$(tail -1 tmpfile |awk '{print $3}')
The rest being the same. Remove the
tempfile afer the work is over. If this is not working, then do check if the last line is a blank line in the
tempfile. Empty lines at the end could also distort the o/p. But I donot know how
postsuper works to clearly identify the cause. Hope that helps!!