The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 08-30-2007
ranj@chn ranj@chn is offline Forum Advisor  
Playing with Ubuntu Now!
  
 

Join Date: Oct 2005
Location: Chennai
Posts: 365
one way

One way would be to get pipe the o/p and filter out the last line and get the no of deleted messages from there & assign it to a variable.

Code:
no_of_msgs=$(mailq | grep -v "^[^0-9A-Z]+" | grep MAILER-DAEMON | awk '{print $1}' | postsuper -d - | tail -1 | awk '{print $3}')

Format the date to get the date-time stamp required

Code:
dt_time=$(date +'%Y%m%d %H:%M')

Now echo this to a file where you want to log this.

Code:
echo "$dt_time - ${no_of_msgs}" >>cron_purges