Solved

Shellscript for MAC-check.

Posted on 2004-04-16
7
296 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
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 50 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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
linux boot fsck problem 3 61
gdb doesn't stop on breakpoint 2 50
How to learn Linux? 10 43
looking for a CENTOS ISO to download with x window installed 2 22
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…
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

895 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now