capture plink failed connection messages to file [duplicate] - windows

This question already has answers here:
How to redirect Windows cmd stdout and stderr to a single file?
(7 answers)
Closed last year.
I am using plink in windows to connect to a network device and capture the output to a file. That part works great.
Here is an example of the command line I am putting in a batch program.
plink.exe -v -l [username] -pw [password] [ip address] -m "c:\empty.txt" < "c:\commands.txt" > "c:\command_output.txt"
command_output.txt only contains the output from the ssh session.
I want to add some error handling in case it cannot connect for example. I can't figure out how to get the connection messages to go to a file. They go to the command window only. I have tried using start /c cmd.exe from another batch program and redirectiong that output to another log file. Tried using 2>&1. I get nothing. It always just goes to the command window.
Here is and example of what I want to capture.
Looking up host "xxx.xxx.xxx.xxx"
Connecting to xxx.xxx.xxx.xxx port 22
Failed to connect to xxx.xxx.xxx.xxx: Network error: Connection timed out
Network error: Connection timed out
FATAL ERROR: Network error: Connection timed out

So, to sum up use the command below. I'm incorporating #Martin Prikryl's suggestion into an answer so this shows as answered.
plink.exe -v -l [username] -pw [password] [ip address] -m "c:\empty.txt" < "c:\commands.txt" > "c:\command_output.txt" 2>&1

Related

How to send the data to TCP PORT using shell script commands

I’m looking for a solution to send the data from a file to the TCP port which is available on the specific server using the shell script/Unix command.
When I checking for this option I found the below one but it’s not working out? Is there any solution is available?
The command I tried from a shell script and find the response below.
Option 1: exec cat /home/data/load.txt > /dev/tcp/$host/$port
-bash: : Name or service not known
-bash: /dev/tcp//: Invalid argument
Option 2:
ncat -v -w 2 hostname 4053 < /home/data/test.txt
Ncat: Version 7.50 ( https://nmap.org/ncat )
Ncat: Connected to xx.xx.xx.xx:4053.
Ncat: Connection reset by peer.
It would be helpful if could someone help with this.
Thanks | SP

plink output redirection fails

I am trying to execute a command file in a remote host.
plink -ssh -P 22 -l abc -pw abc 192.168.44.4 -m "C:\Users\soni\Desktop\cmd.txt" > "C:\Users\soni\Desktop\out.txt"
However this works only if the output is not redirected to file. If I redirect the command output to a file as show in the above command, it results in this error.
FATAL ERROR: Network error: Connection timed out
What am I doing wrong?

shrewsoft command line interface to connect and terminate vpn on ubuntu

Shrewsoft [1] provides a command line interface for setting up the vpn tunnel automatically without any user intervention, such as by using the following command
ikec -u username -p password -r configuration -a
IS there any way to detect if the connect attempt was successful such as by reading live logs and how can we terminate the vpn tunnel after some time using the command line. Any help will be appreciable.
By looking at the terminal output from ikec -u username -p password -r configuration -a, you can tell if the connection was successful; if the output has a line ii : tunnel enabled, that means the connection was successful and should work. If you get a message such as >> : detached from key daemon or failed to connect to key daemon, it means there was a problem with the connection (https://askubuntu.com/a/793336/705434 suggests running sudo /usr/sbin/iked for a solution to this particular error). To exit the ikec command, just type q into the terminal.
EDIT: it looks like this page (https://gist.github.com/fschabmeyer/22b759994cf852df7e9b) has a shell script that can handle the detection, you should be able to add a case to exit the command automatically after a certain amount of time.

Using Plink and redirect output in bash script

I've got problem, I've setup plink to create a connection to a BlueCoat device, retrieve the full configuration and redirect the output to a file.
The problem is, when I try it from the script, the output of plink is displayed on screen and not redirected to the file, but if I use the same exact command interactively, it works!
I've checked the file rights, etc. they all seem to be ok.
The way I use it is:
/usr/bin/plink -4 -batch -ssh -l <user> -pw <password> -m /tmp/bluecoat.backup <hostname> > output.txt
Any clues?
Kind regards,
Chris

mget prompt override

I am using ftp in the command line (terminal) to transfer multiple data files from a remote server to my local computer. There are multiple files (~40) in the directory and I would like to transfer them all without having to answer yes in the prompt for each file. I tried mget * but this only transferred the first file and then a prompt popped up for the second file.
Issue a prompt command first to turn interactive prompting off.
Alternatively, if you have control over the way the ftp command is called, use the command line option, as suggested by #reg-edit:
ftp [-i | --no-prompt] [OPTIONS] [HOST [PORT]]
As an alternative to issuing a prompt command ahead of your other commands, you may invoke ftp with the -i switch.
When you already started ftp you can issue the prompt command to toggle between getting prompted and not getting prompted. So this should do the trick:
> ftp <some server>
ftp> prompt
Interactive mode OFF .
ftp> mget *

Resources