Solved

question about allssh command

  • 20 December 2019
  • 2 replies
  • 4409 views

Userlevel 2
Badge +1

In scripts we use for some ESXi hypervisor configurations we utilize “allssh”.  The problem I’m running in to, though, is I must run each allssh command individually rather than using a script to run multiple allssh commands.  The first line will kick off and before it has a chance to complete the second will kick off.  For example, here’s where we configure DNS on the hypervisor through a CVM:

allssh ssh root@192.168.5.1 esxcli network ip dns server add --server=10.1.1.1
allssh ssh root@192.168.5.1 esxcli network ip dns server remove --server=8.8.8.8
allssh ssh root@192.168.5.1 esxcli network ip dns server add --server=10.1.1.2

The first will kick off then the second goes prior to the first completing.  The script then gets confused and stops while still connected to one of the ESXi hosts.  Does anyone know of a way to initiate subsequent allssh commands only after the prior one running has completed?  Although not very clean, should I put a sleep command in between each?

icon

Best answer by perkinsa 20 December 2019, 19:42

View original

This topic has been closed for comments

2 replies

Badge

@tbailey1  - You can use the below command to achieve the same:

for i in $(hostips); do ssh root@$i esxcli network ip dns server add --server=10.136.100.40; esxcli network ip dns server remove --server=8.8.8.8; esxcli network ip dns server add --server=10.1.1.2; done


Do let me know if the above helps!!

Userlevel 1
Badge +9

@tbailey1

We also have a hostssh command, a wrapper for the above for statement.

You can run it on all hosts with the following syntax.

 

hostssh 'esxcli network ip dns server add -s 10.1.1.1; esxcli network ip dns server remove -s 8.8.8.8; esxcli network ip dns server add --server=10.1.1.2'

 

Cheers,

Art