Skip to content
Advertisement

SSH to multiple machines using a batch file

I have a large number of Linux devices that i want to be able to SSH into and change the netmask. I wanted to create a batch file to do this so that i can export a list of the IP addresses and then run a batch to change the netmask.

I expected my script to be something along the lines of this:

JavaScript

How can i get this to work? am i going along the correct lines?

Advertisement

Answer

You’re very close. However, batch has some nuances that may seem counterintuitive to people used to *nix shell scripting.

Variables need to be set with the set command, and there can’t be spaces on either side of the = sign. This is because you are allowed to include spaces in variable names in batch. Seriously.

Variables are called like %var% instead of $var, but you don’t use the symbols when you’re setting the values.

You don’t need to use cmd.exe to call arp; it’s a perfectly valid batch command. Because of the way arp -a output is formatted, you’re going to want to narrow things down. Find (or findstr) is about as close as you’re going to get to grep.

JavaScript

It should also be noted that Windows has no SSH client natively installed, so you’re going to have to find a third-party solution for that.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement