-2

The below "for" loop works locally on the same server.

But when triggered through "ssh" protocol on remote servers, the output is not received.

Please, can anyone suggest how to make it work while to be triggered on remote servers.

for i in $(cat Server_List)  # Works
do   # Works
echo $i  # Works
ssh $i '$(for a in `/usr/sbin/lspath|grep scsi|awk '{print \$2}'|sort|uniq`;   # Doesn't Work
do    # Doesn't Work
echo "\$a `/usr/sbin/lspath |awk '/'\$a' /' |uniq|awk '/Enabled/'|wc -l`;done)'   # Doesn't Work
done  # Works
5
  • 1
    You have single quotes both in the command you're sending to the remote server and inside the command itself. You'll need to escape the quotes inside the commands you have on the ssh command line. Commented Jul 27, 2023 at 19:43
  • Are you really intending to execute the output of your for loop as a command? Commented Jul 27, 2023 at 19:49
  • @doneal24 - can you pls. write exactly where I would need to escape the quotes as I am just new to these coding area.. thanks.. Commented Jul 27, 2023 at 20:17
  • @roaima - yes as a command through the coding support.. Commented Jul 27, 2023 at 20:19
  • 1
    Try to verify your script into shellcheck.net to see why it doesn't work as intended. Commented Jul 27, 2023 at 21:38

1 Answer 1

0

You can try using heredoc to run a multiline commands via ssh:

ssh user@host <<'EOC' 
  for a in $(/usr/sbin/lspath | awk '/scsi/ {print $2}'| sort -u); do
    # do something
  done
EOC

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.