Operating System - HP-UX
1827280 Members
3045 Online
109717 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...
Kadavan
Occasional Advisor

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

Thank you all your help ..I was able to do completed the script as foollows

while read HOST
do
ssh -n ${HOST} hostname
ssh -n ${HOST} ps aux | grep -v root

done < /home/binu/scripts/hostnames 1> /home/binu/scripts/output 2>&

Thanks
-Binu
Steven Schweda
Honored Contributor

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

> ssh -n ${HOST} hostname

What does that tell you that you didn't
already know?
Kadavan
Occasional Advisor

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

This entry made to update the output file with hostname and then the Process details ..Other wise we cannot make out which process is from which server

Looks like this
cpaiqp4a

USER PID %CPU %MEM SZ RSS TTY STAT STIME TIME COMMAND
tauser02 1396842 0.9 9.0 1385060 1385096 - A Mar 22 824:12 /opt/isv/WAS51
tauser02 3653858 0.4 9.0 1380776 1380812 - A Mar 22 350:33 /opt/isv/WAS51
www 4370646 0.1 2.0 283820 283588 - A Feb 28 243:21 /opt/isv/IBMIH
tauser02 4788304 0.0 1.0 136920 136956 - A Feb 28 55:44 /opt/isv/WAS51
Steven Schweda
Honored Contributor

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

> This entry made to update the output file
> with hostname [...]

Something simple (and local) might be faster:

echo ${HOST}

You're giving the name of the remote host to
"ssh", so that you can ask the remote host to
tell you its name? (I can imagine cases
where you might get a different answer back,
but none seems very likely.)

If you really want the name from the remote
host, do you need two "ssh" sessions?

> ssh -n ${HOST} ps aux | grep -v root

That does the "ps" on the other system, but
it does the "grep" locally, doesn't it? I
haven't tested it, but I'd try to do all the
work on the remote system:

ssh -n ${HOST} 'ps aux | grep -v root'

And, if that worked, then I'd try something
like:
[...] 'hostname ; ps aux | grep [...]'
in _one_ "ssh" command.