Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Shellscript for MAC-check.

Posted on 2004-04-16
7
Medium Priority
?
305 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 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
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.
Suggested Courses
Course of the Month8 days, 11 hours left to enroll

876 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