Linux Bash Script

Intel / AMD
February 11, 2009 at 19:25:08
Specs: Windows XP, 1.1Gig
Hi I am a newbie and I need to write a script for a school project.

1 To write a script to search for network configuration file in the file system and if it's not present then create one using ifconfig.
2 Check to see if Nick card is working, if it is working,then send mail to the current user. If not, use dmesg and check to see if the hardware is installed.
3 Log all this activity to the log file and mail to the user the final status on connectivity.
4 Perform this activity everytime the system boot hostname for Unix network.

It should be an Administrative project and more than 20 lines. I really need help on this bash script.

See More: Linux Bash Script

Report •

February 12, 2009 at 08:05:14
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 > /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 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.

touch /var/lock/subsys/local

That's pretty self exlanatory.

Report •

February 12, 2009 at 18:57:19
Hi Curt R, Thanks. This is pretty cool, It' s almost complete. Right now I am using Fedora 10 and it could be KDE or Gnome. This project should look and feel like any Administrative task of your chosen. The only
concern is, it should be not less than 20 lines and must work. Again Thanks for your help.

Report •

Related Solutions

Ask Question