trackdown/trackdown.sh

55 lines
1.3 KiB
Bash

#!/bin/bash
## Copyright © 2015 Bret Human
## https://cynop.me/
##
## Documentation at:
## https://psi.cynop.me/Caffarius/trackdown
##
## For questions or comments write:
## info@cynop.me
#
# 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 loooooooooooooooooooooooooooooooooooooo
# ooooooooooooooooooooooooooooooooooooong 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