Sponsored Content
Full Discussion: Need some help here
Top Forums Shell Programming and Scripting Need some help here Post 302079777 by Stud33 on Wednesday 12th of July 2006 08:07:30 PM
Old 07-12-2006
Need some help here

Hi, I will try to brief as I know some of you will probably see what im trying to do..

What I am trying to do is have the IP address of the machine compare its IP to the IP that is on the server. I am trying to get it to read the first two octets (10.122.x.x). If the first two octets are different then that of the IP on the server I would like it to send a email to notify that the computers IP has been changed. The reason for this is to keep track of the computer. We have several schools and each school is distinguished by the second octet ("school 1" 10.111.x.x, "school 2" 10.122.x.x". I have the naming of the computer and the email set, I am just stuck on it comparing the first to octets.. Any help is appreciated.


Script:

#! /bin/sh


PATH=/bin:/sbin/:/usr/bin/:/usr/sbin

HWADDRESS=`ifconfig en0 | grep ether | awk '{print $2}'`
IPADDRESS=`ifconfig en0 | grep inet\ | awk '{print $2}'`
SUBNET=`echo $IPADDRESS | awk '{print $2}'`
WEBSERVER='http://10.108.1.227/computer_log/'
NAMEFILE='namelist.txt'
WEBNAMELIST=$WEBSERVER$NAMEFILE
NAMELIST=`curl -fRs -o /tmp/namelist $WEBNAMELIST`
NAMELIST_RESULTS=`grep $HWADDRESS /tmp/namelist | awk '{print $2}'`
IPLIST_RESULTS=`grep $IPADDRESS /tmp/namelist | awk '{print $2}'`
MATCH=`echo $IPLIST_RESULTS | awk '{print $2}'`

###### SET COMPUTERNAME VARIABLE TO CURRENT NAME IF NO VALUE IN NAMELIST OR VALUE IN NAMELIST ######
if [ "$NAMELIST_RESULTS" = "" ]; then
COMPUTERNAME=""
else
COMPUTERNAME=$NAMELIST_RESULTS
fi

###### IF COMPUTERNAME IS BLANK, SET NAME TO HWADDRESS, OTHERWISE SET TO NAMELIST VALUE ######
if [ "$COMPUTERNAME" = "" ]; then
NONAME=`echo $HWADDRESS | awk '{ gsub(":", ""); print $0}'`
ncutil setprop / computer-name $NONAME
ncutil -activate setprop / local-host-name $NONAME
else
ncutil setprop / computer-name $COMPUTERNAME
ncutil -activate setprop / local-host-name $COMPUTERNAME
fi

##### CHECK IP ADDRESS!, AND SEND EMAIL IF COMPUTER IS NOT IN IP RANGE #####

if [ "$SUBNET" = "$MATCH" ]; then
exit
else

sudo postfix start

echo "Computer $COMPUTERNAME has been moved!! The IP address of this machine is now $IPADDRESS" | mail -s "Computer-$COMPUTERNAME has been moved" email@email.org


fi

exit
 
SCRIPT-EMAIL(8) 					  System Administration Commands					   SCRIPT-EMAIL(8)

NAME
script-email - Amanda script to send email notifications DESCRIPTION
script-email is an Amanda script implementing the Script API. It should not be run by users directly. It sends a notification email to the addresses specified in the MAILTO property. PROPERTIES
This section lists the properties that control script-email's functionality. See amanda-scripts(7) for information on the Script API, script configuration. MAILTO List of email addresses that will receive an email on command execution. It is a multi-valued property: property "MAILTO" "amanda@domain.com" "sysadmin@domain.com" "amandauser@domain.com" EXAMPLE
In this example, script-email is scheduled to be run before the DLE, on the server. The unqualified email address amanda will be passed to the email system unchanged. The script is then attached to a dumptype, which can then be specified for any DLEs which require notification. define script-tool pre-email { comment "email me before this DLE is backed up" plugin "script-email" execute-on pre-dle-backup execute-where server property "mailto" "amanda" } define dumptype user-tar-email { user-tar script "pre-email" } SEE ALSO
amanda(8), amanda.conf(5), amanda-client.conf(5), amanda-scripts(7) The Amanda Wiki: : http://wiki.zmanda.com/ AUTHORS
Jean-Louis Martineau <martineau@zmanda.com> Zmanda, Inc. (http://www.zmanda.com) Dustin J. Mitchell <dustin@zmanda.com> Zmanda, Inc. (http://www.zmanda.com) Amanda 3.3.3 01/10/2013 SCRIPT-EMAIL(8)
All times are GMT -4. The time now is 10:06 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy