1

I am scripting some command line operations for collecting and parsing specific network metrics from a Palo Alto 5060 firewall. I am using Plink and Windows batch scripting.

@echo off
"C:\path\to\plink.exe" -ssh [email protected] -pw password < "C:\path\to\commands.txt >> "C:\path\to\output.txt"

The content of the commands.txt is simple at the moment.

show interface ethernet1/1

I cannot get this to work. My output.txt has the following results:

Last login: Tue Nov 24 15:43:13 2015 from localhost

show interface ethernet1/1Welcome user.
user@pa5060> show 
[Kuser@pa5060> show interface 
[Kuser@pa5060> show interface ethernet1/1

This isn't the proper output and the entry of the commands confuses me. Has anyone seen something like this? There is a login banner on this device if that is relevant.

2
  • Is this a complete output you are getting? Commented Nov 25, 2015 at 7:32
  • That is the output I received, sanitized for posting of course. Commented Nov 25, 2015 at 14:40

1 Answer 1

1

I'd guess you are missing a new-line at the end of the command.txt, so the command is not submitted.


As for the repeated prompt and the [K sequence:
This is simply because the remote side expects an interactive terminal on your end, and sends ANSI escape sequences to pretty-print an output.

Each line likely starts with the CR (carriage return) character that would cause the interactive terminal to overwrite the previous line. But this does not work, when you redirect the output to a file. Though if you print the file on a terminal (cmd.exe) using type output, you will probably get only the last line.

To make Plink not enable the interactive terminal, use the -T command-line switch:

"C:\path\to\plink.exe" -ssh [email protected] -pw password -T < "C:\path\to\commands.txt >> "C:\path\to\output.txt"

Though even better is to specify the command on PLink command line

"C:\path\to\plink.exe" -ssh [email protected] -pw password show interface ethernet1/1 >> "C:\path\to\output.txt"

or using -m switch:

"C:\path\to\plink.exe" -ssh [email protected] -pw password -m "C:\path\to\commands.txt >> "C:\path\to\output.txt"

The difference is that the commands specified this way are automatically executed in a non-interactive terminal and mainly in an "exec" channel in a more controlled way, then in the "shell" channel you are using when redirecting the input. So you get rid of the "Last login:" message as well as the command prompt (user@pa5060>) and such.

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks for the answer. To follow up, I tried the -m switch first and couldn't get anything to work. I would just get a blank cmd
What does the show interface command do? What kind of output does it have?
It outputs a bunch of metrics about the interface you specify. Bandwidth, MAC address, packet and byte Tx/Rx, etc
So it just dumps some information and exits? Or does it continuously display up to date information (like top does for example)?
What happens if you login with PuTTY with Connection > SSH > TTY > Don't allocate a pseudo terminal checked and type the command?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.