#!/bin/bash
#This script will create a folder inside the ibay "mrtg"
#which is named by the first argument. It will create a
#cfg file inside the /etc/mrtg folder. It will also add
#a line to the script "/etc/mrtg/all-ip" so that crontab
#will run this script which in turn will run mrtg for each
#device. The second argument is the IP address of each
#device to be monitored..This script is best run when
#"all" the workstations connected to it are powered up
#because "cfgmaker" ignores inactive ports when it is run.
# EX:
# Arg1 Arg2
# | |
# [root@e-smith /root]# create-mrtg 10001 10.0.0.1
# Create a "workdir" for this device using the first argument
mkdir -p /home/e-smith/files/ibays/mrtg/html/$1
#create the cfg file for this Ip address using the first
#argument (assumes community string is "public")
perl /usr/bin/cfgmaker public@$2 --global "workdir: /home/e-smith/files/ibays/mrtg/html/$1" --output /etc/mrtg/$1.cfg
#Create an index.html file for this folder using the first variable
perl /usr/bin/indexmaker /etc/mrtg/$1.cfg > /home/e-smith/files/ibays/mrtg/html/$1/index.html
#create an entry in script "all-ip" to run mrtg for each device.
echo "/usr/bin/mrtg /etc/mrtg/$1.cfg;" >> /etc/mrtg/all-ip
#Uncommenting the line below will create a "master" index.htm
#inside the ibay/html directory for all devices.
#Note that this line will create a text file called index.html.
#This should be edited for correct html syntax.
#echo "
Traffic on ports of Device $1 " >> /home/e-smith/files/ibays/mrtg/html/index.html