LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 12-14-2014, 04:21 AM   #1
Billy_6052
LQ Newbie
 
Registered: Dec 2014
Posts: 14

Rep: Reputation: Disabled
Unhappy using grep to output error messages in /var/log/messages and using a loop?


hi

ive created a script where I want to grep out any error messages and colour the word 'error'. the script I have made so far is:

#!/bin/bash
cat /var/log/messages | grep --color=always "error" | tail

when I run the script there is no output.

also I want to use a loop so I am able to chose wheather I want to look in the /var/log/messages or /var/log/boot.log.... is that possible?
 
Old 12-14-2014, 05:11 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by Billy_6052 View Post
ive created a script where I want to grep out any error messages and colour the word 'error'.
Luckily nobody has ever done this before! ;-p
Any particular reason not to use the (previously suggested) multitail, ctail or ccze?


Quote:
Originally Posted by Billy_6052 View Post
the script I have made so far is:
Code:
#!/bin/bash
cat /var/log/messages | grep --color=always "error" | tail
when I run the script there is no output.
Instead tail a file ('man tail') then grep for it:
Code:
tail -f /var/log/messages | grep --color=always "error"

Quote:
Originally Posted by Billy_6052 View Post
also I want to use a loop so I am able to chose wheather I want to look in the /var/log/messages or /var/log/boot.log.... is that possible?
Either select files by providing them as argument to your script, by using a selector with say "getopts" (in BASH shell: 'help getopts') or use "select" (in BASH shell: 'help select').


*Also note this about the 3rd or 4th thread on the same subject so please keep your topic in one place from now on, OK?
 
1 members found this post helpful.
Old 12-14-2014, 07:58 AM   #3
Billy_6052
LQ Newbie
 
Registered: Dec 2014
Posts: 14

Original Poster
Rep: Reputation: Disabled
hi

thanks for the reply! will check that out I didn't use multiwall as the command does not exist.
 
Old 12-14-2014, 10:28 AM   #4
Billy_6052
LQ Newbie
 
Registered: Dec 2014
Posts: 14

Original Poster
Rep: Reputation: Disabled
i tried what you said, putting the tail -f first, still no output.

also im confused with getopt. how would I select a file as an argument, I looked at the man page and help and I looked online and I cant understand it

Last edited by Billy_6052; 12-14-2014 at 10:33 AM.
 
Old 12-14-2014, 11:01 AM   #5
SAbhi
Member
 
Registered: Aug 2009
Location: Bangaluru, India
Distribution: CentOS 6.5, SuSE SLED/ SLES 10.2 SP2 /11.2, Fedora 11/16
Posts: 665

Rep: Reputation: Disabled
if
Code:
tail -f /something/ | grep <somethingelse>
doesn't gives you expected
then there is no output for your search term at current.

to view last errors you may try using tail without -f option else giving a limit of -100 lines or using
Code:
 grep <somethingelse> filename
they can give you an output if there is any.. although i would not suggest using grep directly, the output could be huge depending upon the search term used.

Last edited by SAbhi; 12-14-2014 at 11:02 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Howto tail -f /var/log/messages | grep isdninfo Mopp Programming 4 07-22-2011 10:00 AM
How can I grep/sed the ips only from /var/log/messages? abefroman Programming 1 07-31-2009 01:47 PM
From where am i getting error messages to /var/log/messages? prabhuacsp Programming 3 02-16-2005 08:59 AM
From where am i getting error messages to /var/log/messages? prabhuacsp Linux - Networking 1 02-16-2005 12:34 AM
No output to /var/log/messages or ~syslog eelriver Slackware 5 07-18-2004 05:13 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 03:31 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration