#!/bin/bash # # Script Name: ipcheck # # Homepage: http://www.scrounge.org/ipwatch/ # # Email: ipwatch@scrounge.org # # Version: 1.1 # # Date: 04/16/2000 # # Requires ipwatch.sh, 0.01 Beta 09, or later # # Copyright (C) 1999, 2000 Bruce Buhler, Wayne Larmon # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # Purpose: Checks the funcionality of ipwatch.sh, # # Usage: Run ipwatch.sh with appropriate command line arguments. # # -c Displays status on console # -c -m Sends status message to address defined with MAILTO # -c -l Writes status to log file # -c -n Suppresses display on console # -c -v Display all variable settings # -c -s Show ipwatch log file # # Can also specify options verbosely: # # -c or --check # -m or --mail # -l or --log # -n or --noecho # -v or --variable # -s or --show # # Configuration is in ipwatch.sh. ipwatch.sh and # ipcheck.sh must be in the same directory. # # See http://www.scrounge.org/ipwatch/ for full instructions # on how to install and configure this script. MSGFILE="/tmp/ipcheck.msg" # Get command line parameters CHKMAIL=""; CHKECHO="1"; CHKLOG=""; CHKINIT=""; CHKVAR=""; CHKSHOW="" while [ ! -z "$1" ]; do case "$1" in -m | --mail) CHKMAIL="1" ;; -l | --log) CHKLOG="1" ;; -n | --noecho) CHKECHO="" ;; -v | --variable) CHKVAR="1" ;; -s | --show) CHKSHOW="1" ;; *) echo -e "\a\n$1 is an invalid argument." ;; esac shift done # We must have been called from ipwatch.sh # MAILTO won't be defined if we weren't called from ipwatch.sh if [ -n "$MAILTO" ]; then SUBJECT="$MACHIDENT IPWatch check:" # Is ipwatch.sh configured at all? if [ $SERVER != "xxx.xxx.xxx.xxx" ]; then # At least somewhat. Now let's try seeing if we have connectivity. if isnetup; then # Yes! We are connected. # isnetup is a function that is defined in ipwatch.sh IPADDR=`ifconfig | grep -A 4 $EXTIF | awk '/inet/ { print $2 }'\ | sed -e s/addr://` SUBJECT="$SUBJECT Network is up" echo -e "\nThe Network is up." >> $MSGFILE # IPFILE is our previous "current" IP. This is tested against # the IP that ifconfig reports to see if our IP has changed. if [ ! -f "$IPFILE" ]; then echo $IPADDR > $IPFILE SUBJECT="$SUBJECT (Created IP file.)" echo -e "\nIPFILE doesn't exist. Creating it now.\n" >> $MSGFILE else # The getoldip function is defined in ipwatch.sh getoldip if [ "$OLDIP" = "$IPADDR" ]; then SUBJECT="$SUBJECT and $IPADDR is unchanged" echo -e "Current IP $IPADDR is unchanged.\n" >> $MSGFILE else SUBJECT="$SUBJECT and $IPPADDR is different from $OLDIP" echo -e "Current IP $IPADDR has changed. (Old IP was $OLDIP)\n" >> $MSGFILE echo -e "\nRun 'ipwatch.sh' with no command arguments to reinitialize." >> $MSGFILE fi fi else SUBJECT="$SUBJECT Network is down" echo -e "\nThe network is down." >> $MSGFILE echo -e "\nRun 'ipwatch.sh' with no command arguments to restart it." >> $MSGFILE fi # if isnetup? else echo -e "\n Cannot check network because SERVER is not configured.\n" >> $MSGFILE fi # if [ SERVER != "xxx.xxx.xxx.xxx"] # Display the ipwatch.sh defined variables if [ -n "$CHKVAR" ]; then echo -e "EXTIF = $EXTIF (is our Internet connection.)" >> $MSGFILE echo -e "SERVER = $SERVER (is what we test to see if the network is up.)" >> $MSGFILE if [ "$SERVER" = "xxx.xxx.xxx.xxx" ]; then echo "SERVER is not configured! This is bad." >> $MSGFILE fi if [ -n "$FIREWALL" ]; then echo -e "FIREWALL = $FIREWALL (is how we restart our firewall.)" >> $MSGFILE else echo -e "FIREWALL is not set, so we won't be restarting the firewall." >> $MSGFILE fi if [ "$UPDATEHOST" = "yes" ]; then echo -e "UPDATEHOST = $UPDATEHOST We will be updating the hostname." >> $MSGFILE else echo -e "UPDATEHOST = $UPDATEHOST We will not be updating the hostname." >> $MSGFILE fi echo -e "TIMELIMIT = $TIMELIMIT seconds." >> $MSGFILE echo -e "LOGFILE = $LOGFILE (ipwatch.sh and ipcheck.ch log file location.)" >> $MSGFILE echo -e "MAILTO = $MAILTO (status messages will be mailed here.)" >> $MSGFILE # Now do some validity checking for Dynamic DNS stuff case "$DYNDNS" in yi) echo -e "Using yi.org for Dynamic DNS.\n" >> $MSGFILE ;; homepc) echo -e "Using homepc.com for Dynamic DNS.\n" >> $MSGFILE ;; dyndns_com) echo -e "Using dyndns.com for Dynamic DNS.\n" >> $MSGFILE ;; dyndns_org) echo -e "Using dyndns.org for Dynamic DNS." >> $MSGFILE if [ -z "$DYNHOSTNAME" ]; then echo -e "DYNHOSTNAME is not configured. It must be.\n" >> $MSGFILE else echo -e "DYNHOSTNAME is $DYNHOSTNAME\n" >> $MSGFILE fi ;; justLinux) echo -e "Using justlinux.com for Dynamic DNS." >> $MSGFILE if [ -z "$DNSID" ]; then echo -e "DNSID is not configured. It must be.\n" >> $MSGFILE else echo -e "JustLinux DNSID is $DNSID\n" >> $MSGFILE fi ;; dhs) echo -e "Using dhs.org for Dynamic DNS." >> $MSGFILE if [ -z "$DYNHOSTNAME" ]; then echo -e "DYNHOSTNAME is not configured. It must be.\n" >> $MSGFILE else echo -e "DYNHOSTNAME is $DYNHOSTNAME\n" >> $MSGFILE fi ;; *) echo -e "You do not have a Dynamic DNS service defined.\n" >> $MSGFILE ;; esac if [ -n "$DYNDNS" ]; then if [ -z "$USER_ID" ] || [ -z "$PASSWORD" ]; then echo -e "USER_ID and PASSWORD need to be filled out.\n" >> $MSGFILE fi fi echo -e "Current IP is located in $IPFILE. (Currently is `cat $IPFILE`.)" >>$MSGFILE fi # if $CHKVAR if [ -f "/var/lock/subsys/ipwatch" ]; then echo -e "ipwatch.sh \"Lock\" file (/var/lock/subsys/ipwatch) exists. Should it?" >> $MSGFILE echo -e "Type 'ps ax | grep ipwatch.sh' to see if other ipwatch processes" >> $MSGFILE echo -e "are running.\n" >> $MSGFILE fi if [ -n "$CHKSHOW" ]; then echo -e "\nLog file is $LOGFILE. Last 10 lines:\n`tail -n 10 $LOGFILE`\n" >> $MSGFILE fi if [ ! -z "$CHKMAIL" ] && isnetup; then mail -s "$SUBJECT" $MAILTO < $MSGFILE fi if [ ! -z "$CHKECHO" ]; then cat "$MSGFILE" fi if [ ! -z "$CHKLOG" ]; then echo "`timestamp` $SUBJECT" >> $LOGFILE fi rm -f $MSGFILE exit else echo -e "\a\nYou can't run ipcheck.sh all by itself." echo -e "You must run ipwatch.sh with the following parameters:\n" echo -e "-c Displays status on the console." echo -e "-c -m Mails status to MAILTO address." echo -e "-c -l Writes status to ipwatch log file." echo -e "-c -n Suppresses display on console." echo -e "-c -v Displays variable assignments." echo -e "-c -s Shows ipwatch log file.\n" echo -e "Can also use verbose options:\n" echo "-c or --check, -m or --mail, -l or --log, -n or --noecho, -v or --variable," echo "-s or --show." echo "" fi # # End of script #