Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Shellscript for MAC-check.

Posted on 2004-04-16
7
Medium Priority
?
303 Views
Last Modified: 2010-04-20
i need a sh-script which will issue a reboot unless the MAC adress of eth0 and eth1 are the correct ones.

(For some reason, a system we have swaps eth0 and eth1 around about once in every 20 reboots.)
0
Comment
Question by:j2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 45

Expert Comment

by:sunnycoder
ID: 10841252
Hi j2,

> (For some reason, a system we have swaps eth0 and eth1 around about once in every 20 reboots.)
Are you sure ? MAC addresses are hardcoded into the device :o)

Linux on booting names the dvices sequentially (if they have not been already named) ... I guess you are being troubled by that naming

Sunnycoder
0
 
LVL 1

Expert Comment

by:ipuschner
ID: 10841263
Hi!

Why that complicated?! How about this script:
<script>

#! /bin/bash
#Idea by Igor Puschner
ifconfig eth0 down
ifconfig eth1 down
ifconfig eth0 hw ether XX:XX:XX:XX:XX:XX
ifconfig eth1 hw ether YY:YY:YY:YY:YY:YY
ifconfig eth0 up
ifconfig eth1 up

</script>


Just replace XX:XX:XX:XX:XX:XX with the Mac Adress for eth0, and YY:YY:YY:YY:YY:YY with the MAc adress for eth1.
It should work fine, as long as eth0 and eth1 have both the same speed (i guess so).
No reboot needed!

Greets Igor
0
 
LVL 20

Accepted Solution

by:
Gns earned 200 total points
ID: 10841410
just for completeness... The very simple "check-n-reboot" script:
#!/bin/bash
ETH0MAC="......"
REALMAC="$(/sbin/ifconfig eth0 | awk '$0 ~ /HWaddr/ {print $NF}')"

if [ "$ETH0MAC" != "$REALMAC" ]
then
  echo "REBOOTING DUE TO MAC MISSMATCH"
  sleep 3
  /sbin/reboot
fi
# End of script

Needs to run after network initialization... perhaps from /etc/rc.local (or similar construct that come very late in the bootup process).

-- Glenn
0
Learn by Doing. Anytime. Anywhere.

Do you like to learn by doing?
Our labs and exercises give you the chance to do just that: Learn by performing actions on real environments.

Hands-on, scenario-based labs give you experience on real environments provided by us so you don't have to worry about breaking anything.

 
LVL 12

Author Comment

by:j2
ID: 10841545
ipuschner: Sorry, that is not what i want. For more then one reason, i _need_ the system to reboot when it happens.

Gns: Thanks, i realize that i simply do not master the "if" statement in shell programming. Thanks.
0
 
LVL 12

Author Comment

by:j2
ID: 10841563
sunny coder: Well, whatever the reason is, some times the "wrong" NIC becomes eth0, which can be a nuisance since the system is a firewall.
0
 
LVL 20

Expert Comment

by:Gns
ID: 10841771
:-) j2.
One not to uncommon solution is to have heterogenous NICs... So that you actually load different modules for the different interfaces.
I have a nagging feeleing I've seen something very nice for this with homogenous NICs (very likely would be completely driver dependant)... Oh for better memory...:-)

-- Glenn
0
 
LVL 12

Author Comment

by:j2
ID: 10844046
Nope, Two different NIC's, different line-speeds, and 802.11q enabled on one :)

I figure that running your script as an "up" script (debian) for eth1 should take care of it.

Have a pleasent weekend!
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
Fine Tune your automatic Updates for Ubuntu / Debian
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

664 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question