Means to check if some process is running on "n" number of machines

Team,

I would like to know, if we have any command in Solaris to verify, if some process is listening on a port on a set of machines.

for eg: Wrote the below script, and found that when a process is listening on that port, then it just waits there and doesnt come out. Rather, I would like the script to verify, if some process is listening on that port on that machine and then come out with appropriate message and process to verify a port on the next machine.

telnet abc 33
telnet xyz 405
telnet bbb 54

Do we have any other alternative? Does lsof be useful? Please let me know on this.

Thanks
Sunil Kumar

First exchange ssh keys with all those servers and then:

# ssh root@abc "netstat -a -f inet -P tcp | grep '.33 '" | awk '{print $NF}'
# ssh root@xyz "netstat -a -f inet -P tcp | grep '.405 '" | awk '{print $NF}'
# ssh root@bbb "netstat -a -f inet -P tcp | grep '.54 '" | awk '{print $NF}'

Above should return word "LISTEN"
Of course you can add some 'if' in script which will return true or false depends of what is the returned word.

Can I exchange the keys using a script with multiple machines? If yes, then can you please tell me how?

I dont want to login to SSH, rather just check, if its running on the remote machine, since I am not aware of the user credentials.

Thanks
Sunil Kumar

If you don't want to use ssh, then you can try nmap.

Hi GP,

Can you please tell me as how to exchange ssh keys with all those servers using a script, without user intervention?

Thanks
Sunil Kumar

Exchanging ssh keys is a one off exercise; there's no reason nor benefit for a script.

Depending on the protocol, this might work:

read foo < /dev/tcp/abc/33  && echo port  33 is open on host abc
read foo < /dev/tcp/xyz/405 && echo port 405 is open on host xyz
read foo < /dev/tcp/bbb/54  && echo port  54 is open on host bbb