-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
I was noticing that although the Hostsonline script was finally updating correctly as far as displaying the hosts, it was appending blank lines to the end of the file, which caused a gap in between itself and the module below it. So instead of using "cp" to transfer the host names from .hostsonlinetmp and .hostsonline, I'm now using sed, which will also cp the contents over, while at the same time removing blank lines. Heres the updated script, which is now available with the others in the rather primitive download section.
// Start of Script
#!/bin/sh
#
# Script by Jason Gotti (email removed for spambots)
# Written and tested on Ubuntu 7.10.
#
# Developed for use with conky, but also can be used
# for other information related purposes. Essentially
# this script will create a file in your home directory
# called ".hostsonline," which will update every thirty
# seconds, and will contain a list of all IP Addresses
# currently assigned on your current network.
#
# Initial variables. Change "ath0" to reflect your network interface. (Check in "ifconfig")
# You also need to install nmap, apcalc, and dog for this script to function correctly..
addressrange=$(ifconfig ath0 | grep "inet addr" | awk -F: {' print $2 '} | awk {' print $1 '} | awk -F. '{ print $1,".",$2,".",$3,".",0,"/24" }' | tr -d " ")
numberofhosts=$(nmap -sP $addressrange | grep Host | wc -l)
currenthost=1
host=$(nmap -sP $addressrange | grep Host | dog -l $currenthost | awk '{ print $2 }')
repeat=1
while [ $repeat = 1 ]
currenthost=1
host=$(nmap -sP $addressrange | grep Host | dog -l $currenthost | awk '{ print $2 }')
do
while [ $currenthost -le $numberofhosts ]
do
echo $host >> ~/.hostsonlinetmp
currenthost=$(calc $currenthost+1)
host=$(nmap -$addressrange | grep Host | dog -l $currenthost | awk '{ print $2 }')
done
sed '/^$/d' ~/.hostsonlinetmp > ~/.hostsonline
rm ~/.hostsonlinetmp
sleep 30
done
// End of Script
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
iD8DBQFHrKqeTiCACtcRvugRAtQmAJ9XlRs8Q6STrqx+atRFv5EPvn7tLwCfRgYj
jJ/iUNjTGfscJ10o6AGrCB0=
=rHa9
-----END PGP SIGNATURE-----
No comments:
Post a Comment