0

I'm trying to run some commands from ssh. There are multiple variables in each remote server.

for db_serv in `olsnodes`; do
   for db_ins in `ssh $db_serv ps -ef | grep ora_pmon_ | grep -v grep | cut -d"_" -f3`; do
   SessionSayisi=`ssh $db_serv ps -ef | grep $db_ins | grep 'LOCAL=NO'|grep -vc ASM`
   echo "SessionSayisi= $SessionSayisi $db_ins"
   done
done

This works well but takes long time because the command is running ssh for each variable. I need to connect only one time for each server, then get all variable outputs, then ssh to another.

Here is what i tried but it didn't work:

 for db_serv in `olsnodes`; do
ssh $db_serv ps -ef | grep ora_pmon_ | grep -v grep | cut -d"_" -f3 << EOF
for db_ins in `ps -ef | grep ora_pmon_ | grep -v grep | cut -d"_" -f3`; do
echo "SessionSayisi= $SessionSayisi $db_ins"
done
EOF
done
1
  • I can get the name but can't get "$db_ins" variable, it just shows blank. Also it puts an "do" word at last of each EOF. Commented Mar 13, 2014 at 12:06

1 Answer 1

1

It looks like you only need to run one SSH command - if you capture the output in a variable, then you can run the rest of your commands on that variable instead of on the remote machine:

for db_serv in $(olsnodes); do
    procs=$(ssh "$db_serv" ps -ef)
    for db_ins in $(echo "$procs" | grep ora_pmon_ | grep -v grep | cut -d"_" -f3); do
        SessionSayisi=$(echo "$procs" | grep "$db_ins" | grep 'LOCAL=NO'| grep -vc ASM)
        echo "SessionSayisi= $SessionSayisi $db_ins"
    done
done
Sign up to request clarification or add additional context in comments.

1 Comment

That solved my problem, thank you. I'll mark it as solution after 5 minutes(site rule).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.