Shell Script to find a string in server(s) log file

Hello Experts.

I want a shell script to find out the Pin Code to enter to the secure servers.

Setup: Pin is generated any one of our Four servers( Ex: pinser1,pinser2,pinser3,pinser4). whenever user is trying to access a secure server, A pin code is generated on above mentioned servers and always users are grepping the pin code in server file using his employee number. A user always entered to the four servers and searching the  pin code.

To overcome this issue, I want a shell script to search all servers and print the Pin code with the help of his employee code.

For example

1) Once he run the script, it should ask his employee number ( Ex: GS66778)
2) After he submitted the Employee Number It should connect to all servers and print the generated pin code.

log path for four servers : /var/log/genpin.log
connecting to servers ssh pin@pinser1 ( All ssh keys are exported to all servers so no need of password authentication)

 ----Enter Employee ID---
----Establish a connection to Four servers---
----search the pin code string in mentioned log files--

Experts please help me.

Thanks in advance.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Alexander Eßer [Alex140181]Software DeveloperCommented:
I suppose, you might need something like this:

read -p -e "Please enter employee ID" empid
echo "You entered $empid"
hosts=(pinser1 pinser2 pinser3 pinser4) # or IP addresses or host names

for host in ${hosts[@]}; do
  echo "== $host =="
  ssh -l pin $host "grep $empid /var/log/genpin.log"


Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
srsysdocAuthor Commented:
Thanks it's working fine.

One more question. Is it possible to search and  get the latest generated Pin code on the four servers.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.