what is the easiest way...

I have a file with the output of my ifconfig that I mail to myself every so often.  How can I tell if the information in the file is different from the current output of ifconfig?  A shell script is what I am looking for...  Thanks.
meetzeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RobWMartinCommented:
Try this,

ifconfig > ifc.new
if [ -z "`cat ifc.{new,old} | sort | grep -v 'packets' | uniq -u`" ]
then
#no change
else
#changed
fi
mv -f ifc.{new,old}


Just answers the question of whether something has changed.  You will need to specify full path for ifc.new and ifc.old.  You will also have to decide what commands to include for both conditions (i.e. no change or changed). Could have used diff, but since the packets are always changing (and you probably don't care about that) then we needed to filter those out.  Still could have used diff, but wouldn't have been quite as short.

Hope this helps,
Rob
0
RobWMartinCommented:
Note:  you'll have to "prime" this with the command:

ifconfig > ifc.old

before running the script.

Rob
0
RobWMartinCommented:
Sorry for yet another note.

Pay close attention to the quote marks in the if condition.  There are double quotes, backticks, and single quotes.  Very important!

Rob
0
Newly released Acronis True Image 2019

In announcing the release of the 15th Anniversary Edition of Acronis True Image 2019, the company revealed that its artificial intelligence-based anti-ransomware technology – stopped more than 200,000 ransomware attacks on 150,000 customers last year.

meetzeAuthor Commented:
The only question I have..what to place in "cat ifc.{new,old}", I understand that one is the old file and other is the new file...
0
RobWMartinCommented:
Not sure what you mean.  cat is a command to list the contents of one or more files.  ifc.{new,old} is a short way of saying ifc.new ifc.old.  It is a bashism.  If bash is not available, you will have to use the longer method.  That reminds me, I didn't put the #! in on line one.  Here it is again:

#!/bin/bash

ifconfig > ifc.new
if [ -z "`cat /var/tmp/ifc.new /var/tmp/ifc.old | sort | grep -v 'packets' | uniq -u`" ]
then
#no change
else
#changed
fi
mv -f /var/tmp/ifc.new /var/tmp/ifc.old

I've also fully qualified the filenames, here.  Don't know if it's obvious to you, but the /var/tmp/ifc.* files contain the output from the ifconfig command.  

Also, you still need to add something after #no change and #changed.  

If you are not interested in getting info until there is a change, then you can shorten the script some more:

#!/bin/bash

ifconfig > ifc.new
if [ "`cat /var/tmp/ifc.new /var/tmp/ifc.old | sort | grep -v 'packets' | uniq -u`" ]
then
#changed
fi

mv -f /var/tmp/ifc.new /var/tmp/ifc.old





0
jyu_88Commented:
1) /sbin/ifconfig eth0|egrep -v "packets|collisions" >if.old

# after a while or a long while, do

2) /sbin/ifconfig eth0|egrep -v "packets|collisions" >if.new

3) diff if.new if.old

If you are interested in ppp0 use it instead of eth0.
egrep ba
0
meetzeAuthor Commented:
There appears to be something wrong..when it does the evaluates the if condition it prints out the contents of the two files then it says that there is no such command.  I have the exact syntax that you have displayed (but i have the correct paths for the files) and it gives the above error.


inet addr:216.7.145.202  Bcast:216.76.147.255  Mask:255.255.252.0
---
>           inet addr:216.76.145.202  Bcast:216.76.147.255  Mask:255.255.252.0:
command not found
there is no change      

0
jyu_88Commented:
The shell script provided has a few things not right
1. you should use 'egrep -v' instead of 'grep -v' to exclude  lines containing 'packets'
2. you need also excludes lines containing 'collisions'

try my 3-step above using 'diff' command.
0
meetzeAuthor Commented:
jyu...it does work, my only probelm is that I am trying to put it in an if statement, but I am having no luck.
0
jyu_88Commented:
#! /bin/bash
/sbin/ifconfig eth0|egrep -v "packets|collisions" >if.new
# it is a pair of back ticks below
diff = `diff if.new if.old | grep -- -`

if [ "NULL$diff" = "NULL" ]
then
      echo "the same"
      # do more stuff here
else
      echo "different"
      # mv if.old if.old.1
      # prepare for next run by update if.old with if.new
      mv -f if.new if.old
fi
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux

From novice to tech pro — start learning today.