#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Posts
    1
    Rep Power
    0

    simple grep question


    I need to get the present month and day and grep the syslog.log file to get the days events.
    i have tried the following:

    #!/bin/sh
    date +"%b %d" > $dt
    grep $dt /var/adm/syslog/syslog.log

    sorry it is so basic but I'm just starting to use unix.

    thanks
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    137
    Rep Power
    0

    Re: simple grep question


    Originally posted by jnau

    #!/bin/sh
    date +"%b %d" > $dt
    grep $dt /var/adm/syslog/syslog.log
    The date format is incorrect, plus sign should be within the double quotes:
    -> date"+%b %d"

    If you want to fill a variable (dt) use the = sign. If you use > the shell thinks that you want to redirect it to a file represented by the variable $dt

    dt = `date"+%b %d"`

    The backqoutes around the complete date command are important.
    Code:
    #!/bin/sh
    dt = `date "+%b %d"`
    grep $dt /var/adm/syslog/syslog.log
    Those 2 lines can be put together:
    Code:
    #!/bin/sh
    grep `date "+%y%m%d"` /var/adm/syslog/syslog.log

IMN logo majestic logo threadwatch logo seochat tools logo