My personal wireless blog

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 ;

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

echo Start Script > log.txtWrite 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