Do you know PLINK?

The last week I need to run a some commands on a lot of APs and output. Today mostly all customer use controllers and don’t need to connect to each ap. But as I learned last week there are still some commands, you can’t run through the controller CLI on all APs :/

For one of my open cases with a vendor I need to run a command on 100+ APs. It was not possible to perform this action from the controller CLI. I need to connect to each AP via ssh, login, run the command and copy the output… Or I use Plink.exe with a simple batch file like in the older days. Plink is a application from PuTTY.

For this job I use 3 files and the Plink application. Let me describe the single files:

command.txt

This file include the commands we need to run. It’s important to include a command that terminate the session and a carriage return at the end to execute the last command. For my small test, I just use „show version“ and „exit“ to terminate the session.

show version
exit

 

host.txt

For the host’s I use a file that also include username and password. It’s also possible create just a list of all host’s and static place the username and password in the batch script. All entries are separated with a , to exclude a line I use the ;

;HOST,USER,PASS
10.10.20.100,admin,12345678
10.10.20.101,admin,12345678

 

run.bat

The last part is the batch script to run the commands on all devices and document the output.

@echo off
echo Start Script > log.txt
for /f „eol=; tokens=1,2,3 delims=,?“ %%a in (host.txt) do (
echo ————————— >> log.txt
echo Host: %%a >> log.txt
echo User: %%b >> log.txt
echo %TIME% >> log.txt
echo ————————— >> log.txt
plink.exe -ssh -l %%b -pw %%c %%a < command.txt >> log.txt
)

 

I’ll now describe the batch file line by line for a easy understanding and quick changes:

echo Start Script > log.txt
Write the first line into log.txt, the > overwrite the last log.txt file

for /f „eol=; tokens=1,2,3 delims=,?“ %%a in (host.txt) do (
this starts the loop and run the following commands for each line added in host.txt. The eol=; is used to mark the ; as symbol to exclude a line, tokens are used for the three options: host,user,pass.

echo ————————— >> log.txt
add a line of – to the log.txt, >> is used to add the information to the log.txt

echo Host: %%a >> log.txt
add the address of the host %%a means first information from the line

echo User: %%b >> log.txt
add the user of the host, %%b used for second information from the line

echo %TIME% >> log.txt
add the time to the log.txt

echo ————————— >> log.txt
add again a line of – to the log.txt

plink.exe -ssh -l %%b -pw %%c %%a < command.txt >> log.txt
-ssh
use ssh for the connection
-l %%b
add the user, %%b is the second option from the line
–pw %%c
add the password, %%c is the third option from the line
%%a
add the host, %%a is the second option from the line
< command.txt
include the commands for the ssh connection
>> log.txt
add the output include commands to the log.txt

)
End the loop.

The result

The result looks like the following:

Start Script
—————————
Host: 10.10.20.100
User: admin
22:27:58,17
—————————
show version
exit
vx9000-01*>show version
VX9000 version 5.8.4.0-034R
Copyright (c) 2004-2016 Symbol Technologies, Inc. All rights reserved.
Booted from secondary because of fallback!
vx9000-01 uptime is 0 days, 00 hours 29 minutes
CPU is Intel(R) Xeon(R) CPU E5-2676 v3 @ 2.40GHz
Base ethernet MAC address is *****
System serial number is *****
Model number is VX-9000-DEMO-WR
vx9000-01*>
vx9000-01*>exit
Using username „admin“.
Start Script
—————————
Host: 10.10.20.101
User: admin
22:27:58,17
—————————
show version
exit
vx9000-02*>show version
VX9000 version 5.8.4.0-034R
Copyright (c) 2004-2016 Symbol Technologies, Inc. All rights reserved.
Booted from secondary because of fallback!
vx9000-02 uptime is 0 days, 00 hours 25 minutes
CPU is Intel(R) Xeon(R) CPU E5-2676 v3 @ 2.40GHz
Base ethernet MAC address is *****
System serial number is *****
Model number is VX-9000-DEMO-WR
vx9000-02*>
vx9000-02*>exit
Using username „admin“.

 

You can find more information in the PuTTY manual.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.


*