sd-slider 0 #1 January 20, 2006 I am trying to clean up multiple syslog digests to make reporting a breeze for my Mgmnt(arrgh!) I basically have a date stamped syslog entry of: Jan 18 13:18:07 10.3.1.99 Elbie, Interface ethernet2, state up The system name varies so there will be multiple if/then/while statements to filter the grep’d output to the appropriate files/variables. My dilemma……I would like to look @ each days date from the date command as follows and force the numeric value on the previous day into a variable and print that variable elsewhere in the script. The problem is n-1 is zero on the first of every month…… Date output: Thu Jan 18 14:43:44 PST 2006 My current script is forcing the current date into $PREVDAY at the end of the script and grep’n the desired values for the current days report (confused?). Anyhoo, the script is as follows: [root@otter scripts]# vi maildev #!/bin/bash ### Get some info cat /var/log/messages | grep Elbie > /home/scripts/lbsum.txt ### SET THE VARIABLES day=`echo $PREVDAY | awk '{print $3}'` month=`echo $PREVDAY | awk '{print $2}'` year=`echo $PREVDAY | awk '{print $6}'` test=`cat /home/scripts/lbsum.txt | grep "$month $day"` ### Set the environment for the next days reporting cycle PREVDAY=`date` ### SEND THE COMPLETED MAIL Mail -s "Dev Awk Script Output for $month $day $year" user@dot.com <$test EOF Any suggestions or shortcuts would be appreciated. I was hoping to have a more “portable” solution that didn’t require volatile variables or static files for storing info. Thanks, =SliderAnvil Brother #69 Sidelined with a 5mm C5-C6 herniated disk... Back2Back slammers and 40yr old fat guys don't mix! Quote Share this post Link to post Share on other sites
AlexCrowley 0 #2 January 20, 2006 Why not just get the previous day using date date --date="yesterday" TV's got them images, TV's got them all, nothing's shocking. Quote Share this post Link to post Share on other sites
sd-slider 0 #3 January 20, 2006 Mr. Crowley, Thanks a *illion. I took the simpler, logical approach(so I thought) and wound up with a headache. Thanks again, =SliderAnvil Brother #69 Sidelined with a 5mm C5-C6 herniated disk... Back2Back slammers and 40yr old fat guys don't mix! Quote Share this post Link to post Share on other sites
AlexCrowley 0 #4 January 20, 2006 I thougth my method was simpler than how you're setting it up. Like this: day=`date +%a --date="yesterday"` month=`date +%b --date="yesterday"` Or you could pull in the full date string as above and use awk for the fields, really depends on your concept of simple I guess Hope that helped! TV's got them images, TV's got them all, nothing's shocking. Quote Share this post Link to post Share on other sites
sd-slider 0 #5 January 20, 2006 Works much better! ThxAnvil Brother #69 Sidelined with a 5mm C5-C6 herniated disk... Back2Back slammers and 40yr old fat guys don't mix! Quote Share this post Link to post Share on other sites
nathaniel 0 #6 January 20, 2006 If you already know awk, the systime() and strftime() functions of gawk--not regular awk-- also come in handy. eg gawk 'BEGIN {print strftime ("%c", systime() - 86400)}' or in perl, perl -e 'use POSIX;print strftime("%c", localtime(time - 86400));' 86400 being the number of seconds in 1 day.My advice is to do what your parents did; get a job, sir. The bums will always lose. Do you hear me, Lebowski? Quote Share this post Link to post Share on other sites