Spring 2015 CSCI 372 Skills — Modify the boot sequence

The setup

When the following script is executed, it “downloads” a CGI script from our server for the sole purpose of transmitting its MAC and IP addresses.

#! /usr/bin/python
import subprocess
args = ['/sbin/ip', 'address', 'show', 'dev', 'eth0', 'label', 'eth0']
p = subprocess.Popen(args, stdout=subprocess.PIPE)
MACaddr = None
IPaddr = None
for line in p.stdout:
    words = line.split()
    if words[0] == 'link/ether':
        MACaddr = words[1]
    elif words[0] == 'inet':
        IPaddr = words[1].split('/')[0]
if (MACaddr is not None) and (IPaddr is not None):
    reqString = reqString = 'http://arden.cs.unca.edu/getethinfo/index.cgi?macaddr=' + MACaddr + '&ipaddr=' + IPaddr
    subprocess.call(['/usr/bin/wget', '-q', '-O', '/dev/null', reqString])

The task

Modify the startup files in your system so that this script is run at system startup.

I suggest you keep it simple. Install the script in /usr/local/sbin, install the appropriate boot sequence script in /etc/init.d, and then run update-rc.d.

Look at the Ubuntu man for update-rc.d for a bit more information.