LinuxQuestions.org
Help answer threads with 0 replies.
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 01-31-2011, 11:03 PM   #1
pinga123
Member
 
Registered: Sep 2009
Posts: 684
Blog Entries: 2

Rep: Reputation: 36
Newbie help needed for comparing values


Being linux administrator my task is to keep the machines up and running .Everyday i get a report of list of machines that are up and running.
it would be nice if i get list of machines that are shutdown in comparison to yesterdays report.
for example.If there are 5 machines in my environment
Namely A,B,C,D and E respectively.
Yest report (Running Machines)
Machine A
Machine B
Machine C
Todays Report (Running Machines) .
Machine D
Machine A

I would like to see The Difference between above two cases.
For example
Machine B,C should be reported to derive at conclusion that Machine B and C are shutdown .
How would i include this logic in script?
 
Old 01-31-2011, 11:27 PM   #2
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
Have a look at the diff and perhaps sort commands.

Evo2.
 
1 members found this post helpful.
Old 01-31-2011, 11:35 PM   #3
pinga123
Member
 
Registered: Sep 2009
Posts: 684
Blog Entries: 2

Original Poster
Rep: Reputation: 36
Quote:
Originally Posted by evo2 View Post
Have a look at the diff and perhaps sort commands.

Evo2.
I m working on diff till now i m able to generate this.
How would i avoid listing unnecessary characters like ">" ,"0a1" ,"2,3d2".
Also MachineD is not needed how would i avoid this?


Code:
# diff -s list1 list2
0a1
> MachineD
2,3d2
< MachineB
< MachineC
 
Old 01-31-2011, 11:45 PM   #4
crts
Senior Member
 
Registered: Jan 2010
Posts: 1,606

Rep: Reputation: 448Reputation: 448Reputation: 448Reputation: 448Reputation: 448
Hi,

how about
Code:
grep -f today.report -v yesterday.report
 
Old 01-31-2011, 11:50 PM   #5
pinga123
Member
 
Registered: Sep 2009
Posts: 684
Blog Entries: 2

Original Poster
Rep: Reputation: 36
Quote:
Originally Posted by crts View Post
Hi,

how about
Code:
grep -f today.report -v yesterday.report
If one of the file has empty lines then above code output nothing.
 
Old 01-31-2011, 11:58 PM   #6
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Quote:
Originally Posted by pinga123 View Post
I m working on diff till now i m able to generate this.
How would i avoid listing unnecessary characters like ">" ,"0a1" ,"2,3d2".
Also MachineD is not needed how would i avoid this?


Code:
# diff -s list1 list2
0a1
> MachineD
2,3d2
< MachineB
< MachineC
How about trying "sdiff"?
 
Old 02-01-2011, 12:03 AM   #7
crts
Senior Member
 
Registered: Jan 2010
Posts: 1,606

Rep: Reputation: 448Reputation: 448Reputation: 448Reputation: 448Reputation: 448
Quote:
Originally Posted by pinga123 View Post
If one of the file has empty lines then above code output nothing.
Hm, your sample did not have empty lines so I did not consider this. I preprocessing an option?
Code:
grep -v "$(sed -r '/^[[:blank:]]*$/ d' today)" yest
PS: The output will still have empty lines if yesterday.report has empty lines in it. Not sure if this is an issue. So postprocessing depends on what you want to do with the data afterwards.

Last edited by crts; 02-01-2011 at 12:09 AM.
 
Old 02-01-2011, 01:22 AM   #8
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
Quote:
Originally Posted by pinga123 View Post
I m working on diff till now i m able to generate this.
How would i avoid listing unnecessary characters like ">" ,"0a1" ,"2,3d2".
Also MachineD is not needed how would i avoid this?
diff is quite versatile, I suggest you read the man page.

Cheers,

Evo2.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Comparing Multiple Values in while loop rahulruns Programming 5 10-27-2009 06:59 AM
Help needed in Comparing Red hat and Debian linux_freak_imt Linux - Distributions 4 01-13-2005 09:14 AM
Perl of Wisdom needed for reading in iptables values pjcp64 Programming 5 06-02-2003 06:52 AM
bash - comparing a variable to several values davee Programming 3 05-05-2003 08:26 AM


All times are GMT -5. The time now is 06:42 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration