punkwalrus (punkwalrus) wrote,
punkwalrus
punkwalrus

Bash - Script to connect to all clients on your DHCP leases

This neat SSH Script came from my RHCE Instructor. It basically looks on your DHCP leases on your DHCP server, pings them, and if they respond, try to ssh into them. Good for a few maintenence issues, like using export to make mass changes down the trail.
#!/bin/sh

for i in $(perl -ne 'm/^lease\D+?(\d+\.\d+\.\d+\.\d+)/ ; 
  if ($1 != "") { print "$1\n";}' /var/lib/dhcp/dhcpd.leases) ; 
    do echo "Who's on $i?" ; if ping -c1 -W1 $i &>/dev/null ; 
    then ssh $i w ; else echo "Nobody there!"; 
  fi ; 
done
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments