0

Hello i`m trying to make a script that shows me online users using the arping command.
I want to enable to stop it using Ctrl +C and print me a message : Continue Y/N. And one more thing in the end to print me : We have $wc -l users online. Smth like that.
Can anyone help?

Here is what i did so far :

#!/bin/bash
i=1
while [ $i -lt 190 ] ; do
arping -I eth1 -c 1 10.0.0.$i | grep Unicast
#arp -an | grep "(10.0.0.$i)"
i=`echo $i + 1 | bc`
done
echo " Done "

3
Contributors
5
Replies
6
Views
12 Years
Discussion Span
Last Post by vgersh99
0

Are you sure you'll be able to use Ctrl-C with the shell? I'd be afraid that the script will just stop being interpreted by the shell, and just dump to a prompt. Perhaps you should be looking at some scripting language (Python or Perl, for instance) where you can simply raise an exception whenever Ctrl-C is pressed?

1
#!/bin/ksh

typeset iter=0

trap 'echo "$(date): iter->[${iter}]";exit' INT;

while :
do
   ls /tmp > /dev/null
   iter=$(( iter + 1))
done
Votes + Comments
AWESOME signature! :D
0

Bash.. still has its faults..
#! /bin/csh -f

set client = (10.0.0.2 10.0.0.3)

foreach client ($client)
set status = `arping -I eth1 -c 1 $client | grep "Received 0 response"`
if ($#status > 0) then
#echo "$client is dead"
else
echo "$client is online"
endif
end

Now when i press Ctrl+C it stops..
I guess i`ll try perl

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.