0

I am running a for loop around 3000 volumes within a ssh connection on a storage Server where this runs in a loop one by one, whereas i want the command vol show-footprint "$vols" -fields volume-blocks-footprint,volume-blocks-footprint-bin0,volume-blocks-footprint-bin1 to run parallel over multiple volumes at a time, lets say run it at 10 volumes in a go.

Here myTotalVol contains all 3k volume names like below:

myvol001
myvol002
myvol003
myvol004
myvol005

Below is the small for loop which is working.

for vols in $(cat myTotalVol);
do 
    echo -n "$vols " ;\
    ssh storageServer01 "row 0; set -unit MB; \
    vol show-footprint "$vols" -fields volume-blocks-footprint,volume-blocks-footprint-bin0,volume-blocks-footprint-bin1"; \
done

Please suggest if I can run the mentioned command over multiple volumes at a time which are kept in myTotalVol file.

Edit:

As asked by Mark Setchell in the comment section, hence below is just a view how its working ...

$ ssh store01
Last login time: 6/30/2022 10:49:41
store01::> row 0;set -unit MB
  (rows)
store01::> vol show-footprint myvol001 -fields volume-blocks-footprint,volume-blocks-footprint-bin0,volume-blocks-footprint-bin1
vserver  volume               volume-blocks-footprint volume-blocks-footprint-bin0 volume-blocks-footprint-bin1
-------- -------------------- ----------------------- ---------------------------- ----------------------------
myvol001 myvol00198703MB                 48272MB                      51988MB

as you see the command vol show-footprint myvol001 -fields volume-blocks-footprint,volume-blocks-footprint-bin0,volume-blocks-footprint-bin1 here, i have to run this command over 3000 Volumes like i have myvol001 in this command so, myvol001 will go into the variable like i am using into the for loop and there i am using "$vols" which are referring to 3k vols from a file.

tripleee
  • 175,061
  • 34
  • 275
  • 318
user294110
  • 145
  • 1
  • 2
  • 14
  • I don't find your question very clear. The title says you want to run a single `ssh` connection, but your code starts 3000 `ssh` connections? – Mark Setchell Jun 30 '22 at 15:47
  • @MarkSetchell i didn't say to run 3k ssh connection rather i want 3k commands to be run in a single ssh connection if you see my for loop then you can understand what i'm trying to do, you are expert .. – user294110 Jun 30 '22 at 15:52
  • I still don't understand. If there are 3000 lines in `myTotalVol`, you will run `ssh` 3000 times? – Mark Setchell Jun 30 '22 at 15:54
  • Does a command like this work? `printf "row 0;set -unit MB\nvol show-footprint myvol001 -fields volume-blocks-footprint,volume-blocks-footprint-bin0,volume-blocks-footprint-bin1\n" | ssh store01` – Mark Setchell Jul 01 '22 at 06:50
  • You seem to have missed several important points from David C Rankin's answer to you two questions ago. Most importantly, http://shellcheck.net/ can point out and even fix many common beginner errors in shell scripts. – tripleee Jul 01 '22 at 09:14
  • Did you try my answer at all? How did you get on? – Mark Setchell Jul 21 '22 at 20:27
  • @MarkSetchell, I did tried your answer which i like but i opted [code-review Second answer](https://codereview.stackexchange.com/questions/278123/bash-script-using-ssh-to-sum-disk-usage-on-netapp/278196#278196) here.. i would live see if you suggest something on that same – user294110 Jul 22 '22 at 06:45
  • Sorry, LDAP and NetApp and other stuff in there are not *"my thing"*. – Mark Setchell Jul 22 '22 at 08:36

1 Answers1

1

I'm not sure exactly what you are driving at, but you should be able to make a compound statement that generates the commands you want and then send that via ssh like this:

{ printf "row 0; set -unit MB;\n"
  while read -r vol ; do 
     printf "vol show-footprint ${vol} -fields volume-blocks-footprint,volume-blocks-footprint-bin0,volume-blocks-footprint-bin1\n"
  done < myTotalVol } | ssh store01

You can try it out and see what it produces if you put a comment character before the | like this:

{ ...
  ... 
  done < myTotalVol } # | ssh store01

Or you can do it with awk:

awk 'BEGIN{print "row 0; set -unit MB"} {print "vol show-footprint", $1, "-fields volume-blocks-footprint,volume-blocks-footprint-bin0,volume-blocks-footprint-bin1"}' myTotalVol | ssh store01

Again, put # in front of | ssh store01 in order to see and check the output without sending it to ssh.

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
  • 1
    You want to avoid https://mywiki.wooledge.org/DontReadLinesWithFor too. The whole subshell would be more idiomatic, elegant, and fast as an Awk script. – tripleee Jul 01 '22 at 08:49
  • @triplee I have tried to implement your suggestion. Further comments/suggestions are welcome, as always. – Mark Setchell Jul 01 '22 at 08:55
  • Looking good. Of course, there is no parallelism here; the OP's earlier question had some hints as to what they wanted to parallelize, but it was much more unclear. This is probably a step in the right direction, at least. – tripleee Jul 01 '22 at 09:07
  • @triplee Yes, I was coming to the *"parallel"* aspect next ... once we get the sequential solution working. – Mark Setchell Jul 01 '22 at 09:09
  • 1
    Tangentially, you can easily avoid the [useless `cat`](https://stackoverflow.com/questions/11710552/useless-use-of-cat): `while read -r vol; do ...; done – tripleee Jul 01 '22 at 09:12