Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple Script?

Status
Not open for further replies.

iceman4000000

Programmer
Jun 7, 2001
30
0
0
GB
Hi everyone, I have a file containing just a column of numbers. Percentages to be precise. This file is named "temp1". I am trying to write a simple shell script that will take the last two numbers in the column and compare them. The idea is, that these numbers are produced from a cron job which measures disk space (df -k) and outputs the percentages to "temp1". I will then tail -2 temp1. The problem is, how do I compare the number values on the two lines? I'd greatly appreciate your help...

iceman
 
cmp compares to files

It may help

Syntax cmp [ -l ] [ -s ] file1 file2
Description
===========
cmp compares two files. By default, if they are different, it displays the byte and line number at which the first difference occurred. If file1 or file2 is ``-'', standard input is used.


-Danny






 
I wrote a script to check diskspace on each partition and build a html page to present the info in coloured bar graphs.
If you'd like me to post it reply here please.
:)
karv
 
Yes Karver,
I would like to see that. Please post your script
thanks
 
iceman4000000,

If I'm understanding this correctly, this should work for you:

#!/bin/ksh

if [ $1 ]
then
TAIL=$(tail -2 $1)
ONE=$(echo $TAIL | awk '{print $1}')
TWO=$(echo $TAIL | awk '{print $2}')
((AVG=(ONE+TWO)/2))
echo $AVG
else
echo &quot;Usage: $0 <filename>&quot;
fi
 
Hi Karver,

I'd love to see that script... it would be so helpful... I'm not too hot on html and am really keen to learn...

iceman4000000
 
heres the script, it also requires some plain text files and a couple of 1 pixel by 1 pixel colored images to make pretty graphs.:

PS Sorry it took so long, I took a sick leave and forgot to come back and post.

This script was designed to run on 7 different machines but post each machines page to our intranet server which is why you'll find each page has a dropdown box linking to each other page.
________________________________________________________
MAIN SCRIPT
---------------
Code:
#!/bin/sh
# Site specific utilities
# Monitoring Disk useage
# written by Karv 17/01/2000
# modified 04/08/2000

set -x

# Cofigurable options START
# Values for identifying colours in html graph, and to trigger e-mail alert
DISK_FULL=95.00
LOW_SPACE=85.00
NORMAL=1.00
FINAL_DIR=wo3.woeth.com:/usr/local/apache/htdocs/rep/

#set location, page description and title 
# NB these values are changeable here as the *top.txt will become generic
DEPOT=Thornbury
SCODE=th
PAGE1=DISK_SPACE
TITLE=Disk_usage

# Set Variables
# Date
D1=`date +%d/%m/%y%n`

# Time
D2=`date +%H:%M:%S`

# Day
D3=`date +%a`

# Logfile
LOG1=hddspace.log

#Begin creating index page
	cat idle_top.txt | sed 's/DEPOT/'$DEPOT'/;s/TITLE/'$TITLE'/;s/PAGE/'$PAGE1'/;s/_/ /' | dtox > ${SCODE}_${SCODE}_diskspace.htm
	echo '<div align=&quot;center&quot;><font color=&quot;#FFFFFF&quot;><b>DATE:</b>'$D1'<b> TIME:</b>'$D2'</div></font>' >> ${SCODE}_diskspace.htm
	echo '<div align=&quot;center&quot;><table width=&quot;90%&quot; border=&quot;0&quot;><tr><td width=&quot; &quot;><div align=&quot;center&quot;><b><font color=&quot;#FFFF00&quot;><u>Partition</u></font></b></div></td><td><div align=&quot;center&quot;><font color=&quot;#FFFF00&quot;><b><u>Total</u></font></b></font></div></td><td><div align=&quot;center&quot;><font color=&quot;#FFFF00&quot;><b><u>USED</u></font></b></font></div></td><td><div align=&quot;center&quot;><font color=&quot;#FFFF00&quot;><b><u>Graph</u></font></b></font></div></td><td><div align=&quot;center&quot;><font color=&quot;#FFFF00&quot;><b><u>Percentage</u></font></b></font></div></td></tr>' >> ${SCODE}_diskspace.htm


# ***** Main section ******
# Begin, Identify diskspace
	dfspace | grep '^[^T*]' >> $$_FS
# Log space and date
	echo &quot;-------------- BEGIN LOGGING ---------------&quot; >> $LOG1
	echo &quot;*** $D1 $d2 ***&quot; >> $LOG1
	dfspace | grep '^[^T*]' >> $LOG1
	echo &quot;------------- END OF LAST LOG ---------------&quot; >> $LOG1
	echo &quot;                                             &quot; >> $LOG1
# End log
# Get drives
	DRIVES=`egrep '^' $$_FS | awk '{ print $1 }'`
	for DRIVE in $DRIVES
	do
# Identify space, used and percentage
	USED=`egrep '^'${DRIVE}'[^A-Za-z]' $$_FS | awk '{ print $5 }'`
	TOTAL=`egrep '^'${DRIVE}'[^A-Za-z]' $$_FS | awk '{ print $8 }'`
	PERCENT=`egrep '^'${DRIVE}'[^A-Za-z]' $$_FS | awk '{ print $11 }' |sed -e 's/(/ /g;s/)\./ /g'`
# Set Colours for web page

	if test &quot;$PERCENT&quot; -ge &quot;$DISK_FULL&quot; ; then
		COLOUR=&quot;#FF0000&quot;
		COLOUR2=red
				
	elif test &quot;$PERCENT&quot; -gt &quot;$LOW_SPACE&quot; ; then
		COLOUR=&quot;#66FFFF&quot;
		COLOUR2=blue
	
	elif test &quot;$PERCENT&quot; -gt &quot;$NORMAL&quot; ; then
		COLOUR=&quot;#33FF33&quot;
		COLOUR2=green
		
	fi
	
# Add drive space to html page
	echo '<tr><td width=&quot; &quot;><div align=&quot;center&quot;><font color=&quot;#FFFFFF&quot;><b>'$DRIVE'</b></font></div></td><td width=&quot; &quot;><div align=&quot;center&quot;><font color=&quot;'$COLOUR'&quot;><b>'$TOTAL'</b></font></div></td><td width=&quot; &quot;><div align=&quot;center&quot;><font color=&quot;'$COLOUR'&quot;><b>'$USED'</b></font></div></td><td><img src=&quot;'$COLOUR2.gif'&quot; width=&quot;'$PERCENT'&quot; height=&quot;10&quot;></td><td width=&quot; &quot;><div align=&quot;center&quot;><font color=&quot;'$COLOUR'&quot;><b>'$PERCENT'</b></font></div></td></tr>' >> ${SCODE}_diskspace.htm

# Option for reporting very low disk space by E-Mail tests space on /u 
# NB: other partitions will naturallybe small and near full by default
	if [ $DRIVE -eq &quot;/u&quot; ] && [ $PERCENT -gt $DISK_FULL ] ; then
# message body
		echo &quot;$DRIVE at $DEPOT has Low Disk Space, it is $PERCENT full &quot; > mailmsg.tmp
		echo &quot;***** This scan will run again in <time set to scan xx> minutes *****&quot; >> mailmsg.tmp
		echo &quot;intranet page can be found at <html addy here>&quot; >> mailmsg.tmp
# send message
		mail -s&quot;Low Disk Space alert!!! $DRIVE $DEPOT&quot; kevinh@th1.theth.com < mailmsg.tmp
		rm mailmsg.tmp
	fi	
done
# finish html
	echo '</table></div>' >> ${SCODE}_diskspace.htm
	cat idle_bottom.txt | dtox >> ${SCODE}_diskspace.htm
# tidyup
	chmod 777 *log
	chmod 777 ${SCODE}_diskspace.htm
	rm $$_FS
# Move all pages to wo3 for intranet availability
	gzip ${SCODE}_diskspace.htm
	rcp ${SCODE}_diskspace.htm.gz $FINAL_DIR
	rcmd wo3.woeth.com gzip -d $FINAL_DIR${SCODE}_diskspace.htm.gz

-------------------------------------------------------
idle_top.txt
------------------------
<html>
<head>
<title>TITLE</title>
<title>
\\Automaticlly Generated Index Page
\\For Baylis Internal Reports
\\Copyright 1999 Company Name
\\Generator Written by Karv 
</title>
<title>TITLE</title>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>
<SCRIPT>
function myFunction(){
	var urlselection = document.urlform.urlpopup.selectedIndex;
	var sitename = document.urlform.urlpopup.options[urlselection].text;
	var siteurl = document.urlform.urlpopup.options[urlselection].value;
	
	{window.location.href = siteurl;}
	}
</SCRIPT>
</head>
<body bgcolor=&quot;#333399&quot; link=&quot;#0000FF&quot; vlink=&quot;#FF0033&quot; alink=&quot;#0000FF&quot;>
<div align=&quot;center&quot;> </div>
<div align=&quot;center&quot;>
  <table width=&quot;99%&quot; border=&quot;0&quot;>
    <tr> 
      <td width=&quot;135&quot;> 
        <div align=&quot;center&quot;><font face=&quot;Impact&quot; size=&quot;+6&quot; color=&quot;#FF0000&quot;>Company</font> 
        </div>
        <div align=&quot;center&quot;><font face=&quot;Times New Roman, Times, serif&quot; size=&quot;+1&quot; color=&quot;#000000&quot;>Name</font> 
        </div>
      </td>
      <td width=&quot;674&quot;> 
        <div align=&quot;center&quot;><font color=&quot;#FFFFFF&quot; face=&quot;Arial, Helvetica, sans-serif&quot;><b><i><u><font face=&quot;Times New Roman, Times, serif&quot;>DEPOT PAGE</font></u></i></b></font></div>
      </td>
      <td width=&quot;135&quot;>
	  </td>
    </tr>
  </table>
</div>
  <hr width=&quot;90%&quot;>
------------------------------------------------------
idle_bottom.txt
---------------------------------
  <p> </p>
    <p></p><FORM NAME='urlform'>
      <div align=&quot;center&quot;><font face=&quot;System&quot; color=&quot;#FFFFFF&quot;>See 
        Disk usage on</font> 
        <SELECT NAME='urlpopup' onChange=&quot;myFunction();&quot;>
          <option value=&quot;wo1_diskspace.htm&quot;> </option>
          <option value=&quot;wo1_diskspace.htm&quot;>WO1</option>
          <option value=&quot;wo2_diskspace.htm&quot;>WO2</option>
          <option value=&quot;wo3_diskspace.htm&quot;>WO3</option>
          <option value=&quot;lb_diskspace.htm&quot;>LB1</option>
          <option value=&quot;pu_diskspace.htm&quot;>PU1</option>
          <option value=&quot;wa_diskspace.htm&quot;>WA1</option>
          <option value=&quot;go_diskspace.htm&quot;>GO1</option>
          <option value=&quot;th_diskspace.htm&quot;>TH1</option>
        </SELECT>
      </div>
	</FORM>
 <div align=&quot;center&quot;>
  <table width=&quot;248&quot; border=&quot;1&quot;>
    <tr> 
      <td> 
	  <div align=&quot;center&quot;><font color=&quot;#000000&quot;><b><font color=&quot;#FF0000&quot;>© 2000 
          Company Name</font></b></font></div>
      </td>
    </tr>
  </table>
</div>
</body>
</html>
--------------------------------------

make 1 pixel x 1 pixel images and call them :
red.gif
purple.gif
green.gif
and modify the bits you need to.
Enjoy :) I can't have sent that email, it says from Superuser.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top