-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.
    – doneal24
    Jul 27 at 19:43
  • Are you really intending to execute the output of your for loop as a command? Jul 27 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.. Jul 27 at 20:17
  • @roaima - yes as a command through the coding support.. Jul 27 at 20:19
  • 1
    Try to verify your script into shellcheck.net to see why it doesn't work as intended.
    – annahri
    Jul 27 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.

Not the answer you're looking for? Browse other questions tagged .