1

I have a environment of 27 Mikrotik Routers and I want to add a user on each one with same credentials.

Normally I had to connect on every Router and click through the GUI to add the user, but now I found a way to use SSH connection via cmd.

I wrote this - which connects on a single Router and performs the Add-User process

ssh admin@10.1.2.3 -password "Passw0rd!" "user add name=customer-support password=#F0ry0u! group=full"

But now I want to make a script which maybe reads in a csv file with the ip adresses of all the routers I want to perform the change on and connect on each Router to execute the command.
Is this possible?

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
IT-4me
  • 11
  • 1

1 Answers1

0

Since SSH is available for MikroTik router, you can indeed read their addresses from a file.

For example, use bash (which you can execute even on Windows through WSL/WSL2 or Git for Windows which includes a MinGW bash)

See for example "Bash Read Comma Separated CSV File on Linux / Unix", here adapted to your case

#!/bin/bash
# Purpose: Read Comma Separated CSV File
# Author: Vivek Gite under GPL v2.0+
# ------------------------------------------
INPUT=data.cvs
OLDIFS=$IFS
IFS=','
[ ! -f $INPUT ] && { echo "$INPUT file not found"; exit 99; }
while read maddress
do
    echo "Address : $maddress"
    # do your SSH call here
done < $INPUT
IFS=$OLDIFS

But if you really need a bat script, see for instance "Help in writing a batch script to parse CSV file and output a text file".

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250