0
sd-slider

*nix Guru's Unite - Shell Script advice/help

Recommended Posts

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,
=Slider
Anvil Brother #69

Sidelined with a 5mm C5-C6 herniated disk...
Back2Back slammers and 40yr old fat guys don't mix!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

0