msgbartop
Tips and Tricks site for advanced HP-UX Engineers
msgbarbottom

09 Feb 17 A Script to identify entries for a particular user

Starting a series on automation scripting.

This one is meant to be run from a master of the universe host, eg a host with root public keys placed on all work servers.

cat searchforid.ksh

 

#!/usr/bin/ksh
#
# test script
#
. ./.scriptenv
# provides standardization for example SSH_CMD="ssh -q -f -o ConnectionAttempts=3 -o ConnectTimeout=10 -o PasswordAuthentication=no -o BatchMode=yes"

LF="${LOGDIR}/${0}.logfile.txt"
> ${LF}
sc=0

uid=$1
date >> ${LF}

awk '{ print $1 }' $serverlist | while read -r hn
do
echo "################### ${hn} searching for user ${uid} ######################"
echo "################### ${hn} searching for user ${uid} ######################" >> ${LF}
if [ "${hn}" != "mygush0" ]
then
  ${SSH_CMD} ${hn} "grep ${uid} /opt/iexpress/sudo/etc/sudoers;grep ${uid} /etc/passwd"
  sleep 5
  ${SSH_CMD} ${hn} "grep ${uid} /opt/iexpress/sudo/etc/sudoers;grep ${uid} /etc/passwd" >> ${LF}

else
  grep ${uid} /opt/iexpress/sudo/etc/sudoers;grep ${uid} /etc/passwd
  grep ${uid} /opt/iexpress/sudo/etc/sudoers >> ${LF};grep ${uid} 
  /etc/passwd >> ${LF}
  echo  
 
 "#######################################################################################################"
echo "#######################################################################################################" >> ${LF}

fi
done
echo "Success count: ${sc} " >> ${LF}

Tags: , ,

sidebarbottom
sidebartop
sidebarbottom
WhatsApp chat