But when I try to execute below script to execute same command on multiple servers, I am getting "0"s instead of column8 and column10. I think block of lines execution syntax does not like --> $8" "$10 in awk.
#!/bin/bash
for server in `cat servers` ; do
sudo ssh $server "bash -s" << EOF
echo "server=$server"
ps -ef | grep rotate | grep 'config' | awk '{print $8" "$10}'
EOF
done
How can I print output from each server in this format?
I suppose the here-document goes to the "sudo"-command, not the "ssh"-command.
Anyways, the command as you wrote it must be wrong (or, to be precise, overly complicated). Whenever a "grep" is piped into another "grep" and/or "awk" then something is to be done:
Btw. i suppose the "sudo" is there for the wrong purpose, because i doubt that only "root" is allowed to do a "ssh". You probably want to connect as "root", which you can achieve in two ways:
On a system where the ps -ef output conforms to POSIX standard requirements, the command:
ps -ef|awk '/rotate/ && /config/{print $8,$10}'
would print the command name and the 2nd argument passed to that command for any commands that contained the strings rotate and config , but that doesn't seem to be what you're showing us. Also note that the standards allow the command and its arguments to be truncated to an implementation-defined line length limit. (And, this could cause the strings you're looking for to be dropped from the ps output you're processing.) Your version of ps may provide options to set various line length limits to control that truncation. What output do you get from the command:
ps -ef|grep rotate
What are you expecting to find in fields 8 and 10 in the ps output?
Don, I am trying to find inventory of what OHS(oracle http server) instances are up and running on each server. We have around 200 ohs instances on 20 servers. I can get these details on each server using awk, please check my initial post. But same command does not work over "ssh" using $> ssh command <<EOF ... EOF syntax.
I think this syntax treats $ and "" differently than executing directly on the server.. How can get same result over SSH also?