0

I'm trying to automate the task of changing settings on 100+ power appliances via SSH but each settings change has multiple interactive prompts. Is this possible or does anyone have an example of how to do this with Python/bash script?

iisor
  • 41
  • 4

2 Answers2

2

Look into expect. Alternative implementations for other languages and systems than Tcl exist (e.g. pexpect for Python or the Ansible expect module).

For 100s of devices, I would particularly look into the Ansible module (I am sure similar modules exist for other systems like salt or chef).

Sven
  • 97,248
  • 13
  • 177
  • 225
  • OK, so still nothing better than expect, but Ansible has an expect module... that sounds interesting. – Law29 Nov 27 '18 at 20:54
  • 1
    @Law29: I've not used it, but at least for somewhat simple cases, pexpect doesn't look too bad. – Sven Nov 27 '18 at 20:57
1

The cloud-generation answer to your question is a programmer-friendly REST API over HTTPS, which your appliances do not seem to have.

The canonical decades-old answer to your question is expect. There is a learning curve there, which may not be worth it when comparing to writing a custom python script, especially if you already know python or if you might want someone else to maintain it in the future.

Between the two, I suspect that writing your custom python script will be the least bad solution, unless some other friendly person here has knowledge of a tool that has escaped my notice.

Law29
  • 3,507
  • 1
  • 15
  • 28