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?
Related
I try to transfer the "test" folder to another server using command shell script scp, then I get an error like:
ssh: connect to host 333 port 22: Invalid argument
lost connection
my script:
scp /test_web/test ssh -i example.pem root#222.111.222.111 -p 333:/web
I'm just learning about shell script, I don't know if there's a syntax wrong or not, I'm very grateful if you can help solve this
I think it is
scp -P 333 -i example.pem /test_web/test root#222.111.222.111:/web
For most programs you can find a man page with synopsis through man {command name}.
For example: man scp
If you encounter further issues, check if you are able to use ssh with root at all. Sometimes root is not permitted to connect via ssh.
I have a batch file
#content of batch file
#echo off
plink.exe -ssh user#IP.address -m C:\Users\My\Documents\command_test.txt -i C:\Users\My\Desktop\PUTTYKEY.ppk
which connects to a remote ubuntu host using plink.exe and runs the following command to set off the script
#content of command_test.txt
/home/user/script.sh
The script requires user input to select files from a second remote host using zenity file selection and an OpenSSH connection
#code snippet from script.sh
ssh -X Remote_vm_user#Remote2.IP.address <<EOF
zenity --title "please select location of data" --file-selection --directory > directory_selected.tmp
echo "========================="
echo "user selected"
cat directory_selected.tmp
echo "========================="
exit
EOF
This works when executing the script directly when connected using PuTTy
However, when executed using the batch file it returns the error;
Pseudo-terminal will not be allocated because stdin is not a terminal.
I have tried using a variety of options to force it as suggested How to deal with "Pseudo-terminal will not be allocated because stdin is not a terminal."
-t and -tt and -T and -t -t
These don't work, no errors are displayed, it just eventually times out
very new to stack overflow so apologies if poor question, suggest edits and I'll amend immediately
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
I'm doing automation for run commands via Plink. Below is required step to run command in my environment:
Login to unix machine:
host: myhost
user/pass: myuser/Mypass
Use command: pbsu - uatwrk1
(Or command: pbrun –u uatwrk1 pbksh)
->it will redirect to other machine and some commands to be executed there
Run some commands
******Issue*******
(I) When I execute the Plink command line below in CMD, I'll get error:
The content of script.txt:
pwd
pbsu - uatwrk1
pwd
runcommand.ksh
plink -ssh myuser#myhost -pw Mypass -m "C:\script.txt" > "C:\log.txt"
Error: "sh: pbrun: command not found"
(II) But it works with command by command:
cmd>plink -ssh myuser#myhost -pw Mypass
$pwd
$pbsu - uatwrk1
$pwd
$runcommand.ksh
Please help to to figure out why the command pbrun failed on (I) while it worked on (II) ?
I need (I) works as it provides the capture log to check further in my automated application (using VBA).
Thanks a ton for any help!
It is possible if in the interactive session (II) you have another environment than in the batch session (I). You must check what PATH and current directory you have in the both cases.
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