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
 
pacmd(1)						      General Commands Manual							  pacmd(1)

NAME
pacmd - Reconfigure a PulseAudio sound server during runtime SYNOPSIS
pacmd pacmd --help pacmd --version DESCRIPTION
This tool can be used to introspect or reconfigure a running PulseAudio sound server during runtime. It connects to the sound server and offers a simple live shell that can be used to enter the commands also understood in the default.pa configuration scripts. To exit the live shell, use ctrl+d. Note that the 'exit' command inside the shell will tell the PulseAudio daemon itself to shutdown! If any arguments are passed on the command line, they will be passed into the live shell which will process the command and exit. OPTIONS
-h | --help Show help. --version Show version information. AUTHORS
The PulseAudio Developers <pulseaudio-discuss (at) lists (dot) freedesktop (dot) org>; PulseAudio is available from http://pulseaudio.org/ SEE ALSO
pulse-cli-syntax(5), pulseaudio(1), pactl(1), default.pa(5) Manuals User pacmd(1)
All times are GMT -4. The time now is 08:55 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy