List/Range Todays Log.

Hi All,
I am mediator Shell programmer, Just have an hands on experice :-), i am writing a shell scirpt to list logs of todays date from /var/log/messages.

I need to ur kind help where if i run this script from cron. the script should filter todays logs only from /var/log/messages.

Below is the script .....

#################################################

#!/bin/bash
set nowrap
date="`date |awk '{print $2 " " $3}'`"
temp1="/root/riskadm.log_`date +%F`"
#temp2="/root/testadm.log_`date +%F`"
grep "$date" /var/log/messages |grep riskadm |grep su >> $temp1

here its not listing todays logs from /var/log/messages.

Kindly assist

Thanks again !

Regards

Hi Anand,

If the date is between the 1st and the 9th of the month you need to add another space between the day and the month in order to grep /var/log/messages, e.g.:

date="Jun  7"

Hi Scrutinizer,
Thanks for your time, I got that but i need this script to automatically take the month and date and extract the logs.I dont have to mentioned June or July etc.. It should automatically list the MOnth and Day logs ...

Thanks !

Hi anand,

Do you mean something like this:

gdate=$(date '+%b %e' | awk '{printf "%s %2s\n",$1,$2}')

or

gdate=$(printf  "%s %2s\n" $(date '+%b %e'))

Which will put today's date in the variable $gdate, so the has the right format to grep /var/log/messages with

Thats something superb... Thanks Scrutinizer