What's wrong with my "grep"


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting What's wrong with my "grep"
# 1  
Old 07-14-2010
What's wrong with my "grep"

So I want dmesg to show out put only from today's date.

I figured this out...........
Code:
root@someserver:/# echo `date` | cut -f2-3 -d " "
Jul 14

Then why does this not work.
Code:
root@someserver:/# dmesg | grep "`date` | cut -f2-3 -d " ""

How can I make grep to evaluate the output of date command, I am sure I am missing something basic.
# 2  
Old 07-14-2010
1. the date command has format specifiers
Code:
var=date "+%b %d"

Read about the %b and %d in the date man page
2.
Code:
 
dmesg | grep -F "$var"

-F means look for a literal text pattern.

your construction needed:
$(date | awk '{print $2 $3}' )
This User Gave Thanks to jim mcnamara For This Post:
# 3  
Old 07-14-2010
I think that the concept is flawed. On my system "dmesg" puts today's date in the heading and then outputs any system messages - even if they happened months ago. The messages themselves are rarely dated.
It is more relevant to look at the log from "syslogd" (the name and location of which depends on the Operating System).

What does your dmesg output look like?
This User Gave Thanks to methyl For This Post:
# 4  
Old 07-14-2010
On solaris 8 the output for today's date is
Code:
root@stagingorcz1:/# dmesg | grep  "Jul 14" | grep -v sendmail
Wed Jul 14 16:35:47 CEST 2010
Jul 14 16:05:43  xntpd[1072]: [ID 774427 daemon.notice] time reset (step) 0.239301 s
Jul 14 16:05:43  xntpd[1072]: [ID 204180 daemon.info] synchronisation lost
Jul 14 16:11:02  xntpd[1072]: [ID 854739 daemon.info] synchronized to 217.147.223.78, stratum=2

so my point is it does sort by date.

---------- Post updated at 10:40 AM ---------- Previous update was at 10:37 AM ----------

My intention was not to make it complicated or to pass the value of $var to grep and use it in a scipt, I just wanted to run it on the command line, how would I do that?
# 5  
Old 07-14-2010
Code:
var=date "+%b %d"; dmesg | grep -F "$var"
# is the same as:
dmesg | grep -F $(date "+%b %d"  )
# the first one is easier for a beginning scripter to get it right

This User Gave Thanks to jim mcnamara For This Post:
# 6  
Old 07-14-2010
I donot want to be annoying but I am sorry it didn't work on my Solaris 8 using bash
Code:
root@someserver/# dmesg | grep -F $(date "+%b %d"  )
grep: illegal option -- F
Usage: grep -hblcnsviw pattern file . . .
Broken Pipe
Broken Pipe

# 7  
Old 07-14-2010
About the shell problem.
Note the "%e" for the day of the week because syslogd date stamps don't have the leading zero on the day.

Code:
DDDMM=`date +"%b %e"`
dmesg|grep "${DDDMM}"


About the concept:
The output from "dmesg" is a limited buffer of messages sent to the system console. It is of little or no use for application monitoring.
In your example the syslog daemon has forwarded some messages to console. I would expect them to appear in one of the main system logs too but if they don't this is a syslog configuration problem.

You can get all sorts of messages from "dmesg" - try the command just after a reboot!
This User Gave Thanks to methyl For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. Shell Programming and Scripting

Failure: if grep "$Var" "$line" inside while read line loop

Hi everybody, I am new at Unix/Bourne shell scripting and with my youngest experiences, I will not become very old with it :o My code: #!/bin/sh set -e set -u export IFS= optl="Optl" LOCSTORCLI="/opt/lsi/storcli/storcli" ($LOCSTORCLI /c0 /vall show | grep RAID | cut -d " "... (5 Replies)
Discussion started by: Subsonic66
5 Replies

3. Shell Programming and Scripting

grep with "[" and "]" and "dot" within the search string

Hello. Following recommendations for one of my threads, this is working perfectly : #!/bin/bash CNT=$( grep -c -e "some text 1" -e "some text 2" -e "some text 3" "/tmp/log_file.txt" ) Now I need a grep success for some thing like : #!/bin/bash CNT=$( grep -c -e "some text_1... (4 Replies)
Discussion started by: jcdole
4 Replies

4. Shell Programming and Scripting

Problem with "find" and "grep" command

I want to list all files/lines which except those which contain the pattern ' /proc/' OR ' /sys/' (mind the leading blank). In a first approach I coded: find / -exec ls -ld {} | grep -v ' /proc/| /sys/' \; > /tmp/list.txt But this doesn't work. I got an error (under Ubuntu): grep:... (5 Replies)
Discussion started by: pstein
5 Replies

5. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

6. Shell Programming and Scripting

ps -ef | grep "string1" "string2" " "string3"

Hi all, can any one suggest me the script to grep multiple strings from ps -ef pls correct the below script . its not working/ i want to print OK if all the below process are running in my solaris system. else i want to print NOT OK. bash-3.00$ ps -ef | grep blu lscpusr 48 42 ... (11 Replies)
Discussion started by: steve2216
11 Replies

7. AIX

xx=`date +"%a %b %d"`;rsh xxx grep "^$XX" zzz ?

AIX 4.2 I am trying to do an rsh grep to search for date records inside server logs by doing this : xx=`date +"%a %b %d"` rsh xxx grep "^$XX" zzz gives : grep: 0652-033 Cannot open Jun. grep: 0652-033 Cannot open 11. But if I do : xx=`date +"%a %b %d"` grep "^$XX" zzz it works... (2 Replies)
Discussion started by: Browser_ice
2 Replies

8. Shell Programming and Scripting

ls -laR | grep "^-" | awk '{print $9}'| grep "$.txt"

Hi, I don't know hot to make this command work: ls -laR | grep "^-" | awk '{print $9}'| grep "$.txt" It should return the list of file .txt It's important to search .txt at the end of the line, becouse some file name have "txt" in their name but have other extensions (13 Replies)
Discussion started by: DNAx86
13 Replies

9. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies

10. Shell Programming and Scripting

grep to find content in between curly braces, "{" and "},"

problem String ~~~~~~~~~~~~~~~~~~ icecream= { smart peopleLink "good" LC "happy" , smartpeopleLink "dull" LC "sad" } aend = {smart vc4 eatr kalu} output needed ~~~~~~~~~~~~~~~~~~ smart peopleLink "good" LC "happy" , smartpeopleLink "dull" LC "sad" smart vc4... (4 Replies)
Discussion started by: keshav_rk
4 Replies
Login or Register to Ask a Question