Trackdown

From Mage
Jump to: navigation, search

A quick and dirty script to report if a user is present on a list of servers.

vi ~/trackdown.sh

#!/usr/bin/bash
##########################################################
#                       Trackdown
#                      Jan 2, 2015
#               Last updated: Feb 19, 2016
##########################################################
# Logs into every server and reports if a user is on it
#
# Prereq: Next to nothing. SSH? Bash?
#
#         If you don't have an ssh key in your ~/.ssh
#         folder this is going to be a looooooooooooooooo
#         oooooooooooooooooooooooooooong process for you.
##########################################################

usage () {
   echo "usage: trackdown.sh -n username"
   echo "You must specify a user to search for."
   exit 1
}

# Get the username to hunt down.
while getopts "n:" option; do
   case $option in
      n) user=${OPTARG};;
   esac
done

if [ -z "$user" ]; then
   usage
fi

# Clean up any previous runs...
rm foundPlaces > /dev/null 2>&1

# File containing a list of servers to hit:
list="serverList"

echo "Press CTRL-C to skip a server, CTRL-D to quit the script."
echo ""

# Loop ALL the servers!
for thisHereServer in $(< "$list") ; do
   trap "echo CTRL-C was pressed" 2
   trap "echo CTRL-D was pressed" 1

   ssh $thisHereServer "id $user | grep uid" > /dev/null 2>&1 &&
      echo "$user found on $thisHereServer" &&
      echo "$user found on $thisHereServer" >> foundPlaces ||
      echo "Nothing on $thisHereServer"
done