LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-07-2016, 01:22 AM   #1
swapnil titar
LQ Newbie
 
Registered: Jul 2012
Location: pune
Posts: 2

Rep: Reputation: Disabled
Unhappy getting is in checking Log files


Hi,

I have one requirement in my project, we need to clean log file location which is having plenty of log files.
but i need to find one string "Messages is InvalidXXXX:" some number like this.

can you tell me how can i do it ?

i am thinking of grep or fgrep, help me out.

Regards,
Swapnil Titar

Last edited by swapnil titar; 03-07-2016 at 01:25 AM.
 
Old 03-07-2016, 05:19 AM   #2
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,481

Rep: Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553
grep to find the string, awk to slice the file name out of the resulting line, rm -f to force the deletion.

What have you done so far?
 
1 members found this post helpful.
Old 03-07-2016, 05:56 AM   #3
swapnil titar
LQ Newbie
 
Registered: Jul 2012
Location: pune
Posts: 2

Original Poster
Rep: Reputation: Disabled
Hi TenTenths,

I have created normal logic right now.here is code stuf. i used only one hard coded log file but i want to check all file at this location. which contains some message like "Invalidxxxxx". I want to find 1st how many file contains that message and the want to place some other loc. then clean up .

1 #!/bin/bash
2 #sceipt for checking file names uniquly and checking unique string in each file
3
4 String path="/home/tmadmin/SwapnilT"
5
6 read -p "Enter the path :" $path
7 if [ -e $path ]
8 then
9 echo " path is present / Exits"
10 fi
11
12
13 cat t2.log | grep "invalid*" | sort | uniq
14
15

If you tell me atleast flow will also help me to proceed further coding ???

Regards,
Swapnil Titar
 
Old 03-07-2016, 06:10 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,930

Rep: Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321
please use [code]here comes your script[/code] to keep formatting
Also
Code:
#instead of:
cat t2.log | grep "invalid*"
#you can use
grep invalid t2.log
Code:
sort | uniq
#is equal to
sort -u
I do not know what is that path good for, but you did not exit if path was present, just message is printed.
 
Old 03-07-2016, 06:12 AM   #5
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,481

Rep: Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553
In this line:
Code:
cat t2.log | grep "invalid*" | sort | uniq
you don't need to cat in to grep, you should just use
Code:
grep "invalid" *
to check all the files in whatever folder you're in.

So the flow would be:
  1. Enter the path you want to check
  2. Use cd to change to that path
  3. grep "invalid" * to find all the files that contain your search
  4. Pass the results of grep in to awk to slice out the filename
  5. Pass that through uniq and wc -l to find the number of files

Repeat the above but use rm -f to remove the file
 
  


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
[SOLVED] Linux log checking script linux_nerd Programming 7 06-12-2015 02:28 AM
checking my server error log Horus1 Linux - Server 3 08-10-2013 02:55 PM
convert screen.log and putty.log files into linux readable files aksharb Linux - Software 1 03-20-2011 07:16 AM
recursive checking and log files (tripwire) wedgeworth Linux - Security 2 05-28-2004 12:20 PM
Can log files be time stamped? (such as FTP login and transfer log files) bripage Linux - Networking 6 08-08-2002 10:55 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:42 PM.

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