Is is possible to have just one script to login to several routers and run a script, rather than manually logging into each router and running that script?
It’s possible via API, but AFAIK, not from scripting itself.
If you don’t like the API syntax much, you can minimize it by saving your desired script as a file (or in /system script) on each router.
In the script that uses the API, you’ll just connect to each router, and execute the script.
Many thanks for your reply - Can the dude be used to send one script to login to several routers and run a script.
I don’t think the Dude could even run a script on a single router… or maybe I’ve missed this ability.
You could “manually” use the Dude to copy a file to each router though.
And you could also use the Dude to invoke a tool (read: executable or a URL) over one or multiple routers. This particular ability could be used to start a custom program that uses the API over said router(s).
You can run a script using The Dude using SNMP Write. You will need to use a third party SNMP agent (such as the free NetSNMP toolkit).
You would configure Dude to execute the snmpset command with the appropriate parameters, using OIDs as described here - http://wiki.mikrotik.com/wiki/Manual:SNMP#Run_Script
Just note that this will only run scripts which are written into routeros’s Scripts window. You cannot run script files (.RSC) in this way.
Interesting - does this still mean that i would have to SNMP run_script on each router, can this action be run as a batch to several routers.
best to use ssh from another box to run cmd’s…
#!/bin/sh
mt=( 1.1.1.1 2.2.2.2 3.3.3.3 4.4.4.4)
for router in ${mt[@]}
do
echo $router
ssh -n -i ~/mt/mt.dsa admin-ssh@$router -p 22 “/ip pool print; /ip pool used print count-only where address~"^2.*"”
done
as an example …
If I recall correctly, if you select multiple objects in Dude and then run the SNMP command as a Command action (like you with SSH and Web access), The Dude executes the command for each object.
Maybe this is a solution:
log to router using SSH
upload script file using SCP or SFTP
execute ‘import file-name=your_script.rsc’ command
delete script file
SSH login to many routers can be automated using plink.exe from PuTTY.
HTH,
Any recommendation to get a list of Mikrotik IPs on my network to feed into this script?
IP Neighbor will only give me adjacent.
IP Scan will get me everything.
it is possible to use ssh in script to run commands on other router. set up private/public key and run the command the usual way
[admin@RB1000-A] > system ssh 10.5.50.1 user=test "/system resource print"
uptime: 1d4h20m55s
version: 5.13rc1
free-memory: 246952KiB
total-memory: 516292KiB
cpu: e500v2
cpu-count: 1
cpu-frequency: 1333MHz
cpu-load: 82%
free-hdd-space: 25804KiB
total-hdd-space: 61440KiB
write-sect-since-reboot: 301
write-sect-total: 1325260
bad-blocks: 0%
architecture-name: powerpc
board-name: RB1000
platform: MikroTik
Welcome back!
[admin@RB1000-A] >
We use routertools in conjunction with the dude.
Has anyone else used that tool? That looks exactly like what I have been looking for.
part of one of my shell scripts to find a list of devices out of the dude:
# getting file from dude server
echo "Authorizing..."
wget --cookies=on --keep-session-cookies --save-cookies=$workdir/cookie.txt --progress=dot:mega --no-check-certificate "https://$server:$serverport/dude/main.html?process=login&user=$user&password=$password" -O $workdir/page1.html 2>> $logfile
echo "Please wait, downloading list of devices."
wget --cookies=on --load-cookies=$workdir/cookie.txt --progress=dot:mega --no-check-certificate "https://$server:$serverport/dude/main.html?page=devices" -O $workdir/devices.html 2>> $logfile
devices=`awk 'match($0, /device_info&id=([[:digit:]]+)/, a) {print a[1]}' $workdir/devices.html`
echo "Recursively looking for Premium flag now."
Just wondering if someone has a technique for running a script on many routers using Dude rather than login into each router?
You can also try this: http://wiki.mikrotik.com/wiki/Manual:Configuration_Management#Automatic_Import
"Automatic Import
Since RouterOS v3rc it is possible to automatically execute scripts - your script file has to be called anything.auto.rsc - once this file is uploaded with FTP to the router, it will automatically be executed, just like with the Import command. "
You can use /tool/fetch to send your local script to other routers.
Many thanks for your reply but it would appear i still have to select one router at a time and login, I wish i could select a group of routers (like in upgrading) and run the file as batch to many routers?
You can create one script containing commands with login details for every router:
/tool fetch address=192.168.88.2 src-path=conf.rsc user=admin mode=ftp password=123 dst-path=123.auto.rsc upload=yes
http://wiki.mikrotik.com/wiki/Manual:Tools/Fetch
It can be inconvenient if the list of routers is changing often but if you have static list it is easy.
In the CPE’s script config i must first enable port21 as it is disabled - then I want to update NTP client - then disable port21 - afterwards?
I cannot answer in private message so I post answer here.
Maybe you can leave port 21 enabled and just set list of networks that it is available from?
…
Maybe you can leave port 21 enabled and just set list of networks that it is available from?
Yes I have done this and this should help with network security?