I use plink to retrive CISCO device information with SSH, it work very well for single command, but I couldn’t get device information if I use a command file, I use plink to connect to a device, run some commands, send the output to a text file on my local system, and exit.
Here is my command line:
plink.exe -ssh myuserid@xxx.xxx.xxx.xxx -pw mypassword -m C:\tmp\commands.txt > C:\tmp\Output.txt
Here is command file – commands.txt file
term length 0
sh ip int br
sh int status
exit
Here is the result in Output.txt file
Line has invalid autocommand “term length 0
sh ip int br
sh int status
exit
I modified the command line to use a comamnd string to instead of command file as following:
plink.exe -ssh myuserid@xxx.xxx.xxx.xxx -pw mypassword “term length 0 ; sh ip int br ; sh int status ; exit” > C:\tmp\Output.txt
I can run the command without any error, but I only can retrive the information for the first command in command string, it means I only can retrive device information for ‘term length 0’
please give me some advice, your help will be appreciated. Thanks
plink.exe -ssh myuserid@xxx.xxx.xxx.xxx -pw mypassword “term length 0 > C:\tmp\Output.txt ; sh ip int br >> C:\tmp\Output.txt; sh int status >> C:\tmp\Output.txt; exit”
another possibility:
plink.exe -ssh myuserid@xxx.xxx.xxx.xxx -pw mypassword -m “C:\tmp\commands.txt” > C:\tmp\Output.txt
or:
(plink.exe -ssh myuserid@xxx.xxx.xxx.xxx -pw mypassword -m C:\tmp\commands.txt) > C:\tmp\Output.txt
as you can see, the piping must be attached to the correct process, or you get garbage. All subprocesses need to be coralled/collected into the final output. Sometimes quotes work, sometimes () works. I’m not expert here, Lol!