linux - SSH to multiple machines using a batch file -


i have large number of linux devices want able ssh , change netmask. wanted create batch file can export list of ip addresses , run batch change netmask.

i expected script along lines of this:

$user = "username" $pass = "password"  dir /b cmd.exe -arp -a>list.txt /f "tokens=1 delims= " %%a in (list.txt) (  echo ssh <ip address list.txt> $user $pass echo sudo ifconfig eth0 netmask 255.255.255.192 echo exit ) 

how can work? going along correct lines?

you're close. however, batch has nuances may seem counterintuitive people used *nix shell scripting.

variables need set set command, , there can't spaces on either side of = sign. because allowed include spaces in variable names in batch. seriously.

variables called %var% instead of $var, don't use symbols when you're setting values.

you don't need use cmd.exe call arp; it's valid batch command. because of way arp -a output formatted, you're going want narrow things down. find (or findstr) close you're going grep.

set user="username" set pass="password"  arp -a|find "interface">list.txt  /f "tokens=1" %%a in (list.txt) (     ssh %user%@%%a 'sudo ifconfig eth0 netmask 255.255.255.192' ) 

it should noted windows has no ssh client natively installed, you're going have find third-party solution that.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -