|Likely the best place to ask would be either the Linux or the UNIX forum.|
I frequent the UNIX forum and I've been learning more about Linux lately thanks to a small project I have on the go at work. I'm still pretty new to both but I will try to help since it gives me practice. Normally though, most of us here don't help much with homework projects.
1) You need to pick a specific OS for this as they all differ somewhat. Linux uses files UNIX doesn't and vice versa. In a nutshell though, once you know which file(s) you are looking for, your script should check for their existence. If they're not there, create them and/or use the ifconfig command to configure the NIC.
2) I suspect a quick ping of any other device (like your gateway) should be good enough. Something like the following:
if ! ping -q -c 1 -w 2 xxx.xxx.xxx.xxx > /dev/null; then
echo "NIC not working" | mail -s "NIC error" email@address
# dmesg stuff from below goes here
In the above, replace the x's with the IP of your gateway.
If you get no response, then use 'dmesg' to check for an installed interface. Again, different OS's use different nomenclature. On my OpenBSD box, the interface is em0 and on the Linux box I'm setting up, it's eth0 so to check you would do something like:
dmesg | grep emo (UNIX)
dmesg | grep eth0 (Linux)
The dmesg portion of your script (using my UNIX box's inferface) should look something like:
# check if NIC is installed
if [ -n 'dmesg | grep em0' ];
echo "em0 is installed"
echo "em0 is NOT installed!"
3) I'd have to play with this but I suspect you could use tee for the above and have it cat output to a text file. Then you just use the mail command to send the file. Something like:
mail "Log file" email@address < /path/to/logfile/filename
4) I just asked one our linux guru's about this as I had no clue.....lol. If you're using Redhat or CentOS, or a derivative of Redhat.....there's a file called rc.local located in /etc/rc.d that runs after everything else. I just cat'd it to the screen and here's what was in it:
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
That's pretty self exlanatory.