Operating System - HP-UX
1748232 Members
3350 Online
108759 Solutions
New Discussion юеВ

Re: Script to get the report of the process running in 30 Servers

 
SOLVED
Go to solution
Kadavan
Occasional Advisor

Script to get the report of the process running in 30 Servers

Hi All

I need you valuable belp in creating a script that will login 30 servers and create a report of the process run by users other that root.

Regards
-Binu
13 REPLIES 13
James R. Ferguson
Acclaimed Contributor
Solution

Re: Script to get the report of the process running in 30 Servers

Hi:

What have you tried?

I suggest using 'ssh -n ' for example to login to a list of servers and return information.

Something driven like:

while read HOST
do
ssh -n ${HOST} ps -ef
done < /home/binu/hostnames

Regards!

...JRF...
Viktor Balogh
Honored Contributor

Re: Script to get the report of the process running in 30 Servers

Kadavan,

for this you will need at least the following:

- a file containing the name of the servers
- ssh keyed access (you don't want to type all the passwords per hand, do you?)

anyway, a while loop would do this, see above...
****
Unix operates with beer.
Kadavan
Occasional Advisor

Re: Script to get the report of the process running in 30 Servers

Hi Victor

Where can I mention the host file details in the the script

Regards
-Binu
Viktor Balogh
Honored Contributor

Re: Script to get the report of the process running in 30 Servers

> Where can I mention the host file details in the the script


it is in the last line, where you specify that file. in our case it's /home/binu/hostnames :

#

while read HOST
do
ssh -n ${HOST} ps -ef
done < /home/binu/hostnames

#
****
Unix operates with beer.
James R. Ferguson
Acclaimed Contributor

Re: Script to get the report of the process running in 30 Servers

Hi (again):

> Where can I mention the host file details in the the script

The file that I showed in my example --- '/home/binu/hostnames' simply consists of a server's hostname, one name per line of the file.

Regards!

...JRF...
Kadavan
Occasional Advisor

Re: Script to get the report of the process running in 30 Servers

Hi Victor

Where will be the output of ps -ef get stored ..Is it possible to store the output of ps -ef of all servers in a single file.

Regards
-Binu
Viktor Balogh
Honored Contributor

Re: Script to get the report of the process running in 30 Servers

> Where will be the output of ps -ef get stored ..Is it possible to store the output of ps -ef of all servers in a single file.

yes, use redirection:

while read HOST
do
ssh -n ${HOST} ps -ef
done < /home/binu/hostnames 1> /home/binu/output 2>&1
****
Unix operates with beer.
Kadavan
Occasional Advisor

Re: Script to get the report of the process running in 30 Servers

Thanks Viktor and James .The script is working .It is asking for password for each host ..Can we do some thih for this

and Is there way to arrange the output file according to the hostname

Regards
-Binu
Mel Burslan
Honored Contributor

Re: Script to get the report of the process running in 30 Servers

Look at Victor's first answer.. You need authorized key pairs between the master and client servers.

If you don't know how to do this, I personally described this process at least in 10 different posts. Look at my answer history and find one of those. It is not hard but it needs precise execution for file ownerships and permissions.

Or search google for creating shh keys for passwordless login and you will find a tgon of documents explaining how to do this.
________________________________
UNIX because I majored in cryptology...