Solved

Shellscript for MAC-check.

Posted on 2004-04-16
7
299 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
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ipconfig not working on windows 10 bash shell; what other commands are missing. 17 349
Run Secure WMI query from CentOS 5 80
Samba Question 11 72
Apache module 5 42
This is the error message I got (CODE) Error caused by incompatible libmp3lame 3.98-2 with ffmpeg I've googled this error message and found out sometimes it attaches this note "can be treated with downgrade libmp3lame to version 3.97 or 3.98" …
Fine Tune your automatic Updates for Ubuntu / Debian
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

792 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