Score:1

How to multiple sshconnection in same bash script via sshpass

cr flag

I'm a bit beginner on linux. Let's imagine a scenario like this. I have 4 different linux machines and these 4 machines have different scripts. From to an another machine, I want to connect to these 4 different machines in the same script and run the scripts on this machines.

I created such a method in my head.

But I am not sure how to make ssh connection to 4 different machines at the same time. I think it should disconnect the ssh connection after it is done on one machine.

Do you think something like this will work or what can I do to make it work?

  #!/bin/bash
  variableA="$1"

  SSHPASS='mypassforsshcon'

  sshpass -p $SSHPASS ssh user@xxx.1 /home/admin/1.sh $variableA
  sshpass -p $SSHPASS ssh user@xxx.2 /home/admin/2.sh $variableA
  sshpass -p $SSHPASS ssh user@xxx.3 /home/admin/3.sh $variableA
  sshpass -p $SSHPASS ssh user@xxx.4 /home/admin/4.sh $variableA

I would appreciate your help.

Score:0
as flag

You can try running them in the background by adding && at the end of every command, that way they will execute at the same time (almost) something like this

  #!/bin/bash
  variableA="$1"

  SSHPASS='mypassforsshcon'

  sshpass -p $SSHPASS ssh user@xxx.1 /home/admin/1.sh $variableA &&
  sshpass -p $SSHPASS ssh user@xxx.2 /home/admin/2.sh $variableA &&
  sshpass -p $SSHPASS ssh user@xxx.3 /home/admin/3.sh $variableA &&
  sshpass -p $SSHPASS ssh user@xxx.4 /home/admin/4.sh $variableA &&
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.