Plink with command file

June 16, 2012 at 05:47:42
Specs: Windows 7
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


See More: Plink with command file

Report •

#1
June 27, 2012 at 20:33:04
just guessing: I have plink but have not had the pleasure of aquaintance:

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!


Report •

#2
June 28, 2012 at 18:01:59
Thank you very much, I appreciate you very much for your suggestions; I tested all, I didn't get success, the main issue was that I only get the result for the first command when I use command string or comamnd file, I am sure that it is OK when I replace output.txt and append output.txt file, it means that the issue is related to Plink commands, here are the test results:

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"

Result:
Line has invalid autocommand "term length 0 > C:\tmp\Output.txt ; sh ip int br >> C:\tmp\Output.txt ; sh int status >> C:\tmp\Output.txt ; exit"

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'

Result:
Line has invalid autocommand "term length 0 ; sh ip int br ; sh int status ; exit"

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

Result:
Same result as first command -
plink.exe -ssh myuserid@xxx.xxx.xxx.xxx -pw mypassword term length 0 > C:\tmp\Output.txt

Here is commands.txt file:

term length 0
sh ip int br
sh int status
exit

plink.exe -ssh myuserid@xxx.xxx.xxx.xxx -m "C:\tmp\commands.txt" > C:\tmp\Output.txt

Result:
Line has invalid autocommand "term length 0
sh ip int br
sh int status
exit
"

(plink.exe -ssh myuserid@xxx.xxx.xxx.xxx -m C:\tmp\commands.txt) > C:\tmp\Output.txt

Result:
Line has invalid autocommand "term length 0
sh ip int br
sh int status
exit
"


Report •

#3
June 28, 2012 at 19:57:04
The only other thing I can think of, is if your equipment uses a specific delimiter other than crlf between "lines". It keeps telling you "line has invalid autocommand", which it did even before I tried putting in the redirects.
Coming from equipt or plink?
You might need to check your cisco equipment specs and see what they want incoming. Some systems use linefeed-only, some car.ret only, some crlf, and some lfcr. Esp if it is unix-based, check for this problem.
Lame response, but best I could come up with lacking a working model to test.

Report •

Related Solutions

#4
June 30, 2012 at 06:58:25
Thank you very much, I appreciate you very much for your help; it is very helpful for your suggestions, I can try some ideas which you have; our equipment use carriadge return, I will try to use carriage return to replace semi common in command string next week. Thanks.

Report •

Ask Question