I am using PuTTY command line to connect to a server and tail a log file. On local machine I've created a file "tail-exec" which contains following text:
tail -f /var/log/test.log
I am starting putty through command line as:
putty -ssh -t -pw -m tail-exec user#server
This opens up the terminal window with log tail. But the problem is that this terminal hangs after there are few hundred lines added to the log.
If I open putty manually, and then run the tail command from the bash prompt, then it is not hanging for thousands of lines also.
I've tried using following text in tail-exec file, but same issue is happening:
bash -i tail -f /var/log/test.log
Any idea what could be the issue?
Try to use a saved session where you set the Option "Keepalive". The use the session like this:
putty -ssh -t -pw -m tail-exec -load 'session-name'
Related
I am trying to make an automation using Power Automate Desktop for PuTTY. I have come across a solution to use cmd to run commands using plink.
I used the following steps:
I added PuTTY to system variables
I used the command (in cmd):
plink -ssh hostname#ipaddress -pw password -no-antispoof -m C:\commands.txt
I edited command.txt:
ssh anotherIP -pw passwordForAnotherIP
cd /tmp
cat filename
When I run the command in cmd, I can not input password for the other server that needs to be accessed inside the first one. The error shown is
Bad Port 'w'
The server runs bash 4.2. How can I input password inside the txt file commands so that command line plink command takes it?
Better solution is using Plink's -proxycmd:
plink -ssh anotherIP -pw passwordForAnotherIP -no-antispoof -proxycmd "plink -ssh hostname#ipaddress -pw password -nc anotherIP:22" -m C:\commands.txt
With the commands.txt containing only the:
cd /tmp
cat filename
To answer your literal question:
The OpenSSH ssh has no -pw switch. See Automatically enter SSH password with script.
Additionally, your command.txt won't do what you think anyway. It won't run the cd and cat within the ssh. It would run them after the ssh. So on the ipaddress. How to do this properly is discussed in: Entering password to remote ssh through Plink after establishing a connection.
I'm using localhost.run to open tunnels, so I want to launch
ssh -R 80:localhost:8080 ssh.localhost.run
The only problem is that I launch it via LSF as part of a bash script.
I get the error
Pseudo-terminal will not be allocated because stdin is not a terminal.
that I solve by using the option
-T Disable pseudo-tty allocation.
My current command is
ssh -T -R 80:localhost:8080 ssh.localhost.run
and it is the last command of my bash script.
I have also tried using -tt with the same result (https://stackoverflow.com/a/7122115/5133167)
When I launch my script from my tty, I get the expected output (a message like Connect to http://user.localhost.run or https://user.localhost.run)
When I launch it through LSF (using bsub), I don't get any output from SSH (but get the output from the other commands).
I have also tried redirecting the output of ssh to a file: it works fine when launched from the command line but not when launched from LSF.
when I run this command
urxvt -e ssh -t my-remote-server tmux new -As default-session in rofi,
urxvt will come out, and exit immeditelly.
the question is: how can I keep urxvt window alive with above situation?
I have tried those, and them all work well.
ssh -t my-remote-server tmux new -As default-session # will attach in the session, unless I detach from the session, this command will not exit.
urxvt -e ssh -t my-remote-server tail -f /dev/null
I tried to use alacritty, it works well
I found the cause: inapproriate TERM env
so the command should be: ssh -t my-remote-server TERM=xterm-256color tmux new -As default-session
another thing to know, remote server must have the TERM type (using in the above command) in /usr/share/terminfo (usualy in there)
I am looking to script something in batch which will need to run remote ssh commands on Linux. I would want the output returned so I can either display it on the screen or log it.
I tried putty.exe -ssh user#host -pw password -m command_run but it doesn't return anything on my screen.
Anyone done this before?
The -m switch of PuTTY takes a path to a script file as an argument, not a command.
Reference: https://the.earth.li/~sgtatham/putty/latest/htmldoc/Chapter3.html#using-cmdline-m
So you have to save your command (command_run) to a plain text file (e.g. c:\path\command.txt) and pass that to PuTTY:
putty.exe -ssh user#host -pw password -m c:\path\command.txt
Though note that you should use Plink (a command-line connection tool from PuTTY suite). It's a console application, so you can redirect its output to a file (what you cannot do with PuTTY).
A command-line syntax is identical, an output redirection added:
plink.exe -ssh user#host -pw password -m c:\path\command.txt > output.txt
See Using the command-line connection tool Plink.
And with Plink, you can actually provide the command directly on its command-line:
plink.exe -ssh user#host -pw password command > output.txt
Similar questions:
Automating running command on Linux from Windows using PuTTY
Executing command in Plink from a batch file
You can also use Bash on Ubuntu on Windows directly. E.g.,
bash -c "ssh -t user#computer 'cd /; sudo my-command'"
Per Martin Prikryl's comment below:
The -t enables terminal emulation. Whether you need the terminal emulation for sudo depends on configuration (and by default you do no need it, while many distributions override the default). On the contrary, many other commands need terminal emulation.
As an alternative option you could install OpenSSH http://www.mls-software.com/opensshd.html and then simply ssh user#host -pw password -m command_run
Edit: After a response from user2687375 when installing, select client only. Once this is done you should be able to initiate SSH from command.
Then you can create an ssh batch script such as
ECHO OFF
CLS
:MENU
ECHO.
ECHO ........................
ECHO SSH servers
ECHO ........................
ECHO.
ECHO 1 - Web Server 1
ECHO 2 - Web Server 2
ECHO E - EXIT
ECHO.
SET /P M=Type 1 - 2 then press ENTER:
IF %M%==1 GOTO WEB1
IF %M%==2 GOTO WEB2
IF %M%==E GOTO EOF
REM ------------------------------
REM SSH Server details
REM ------------------------------
:WEB1
CLS
call ssh user#xxx.xxx.xxx.xxx
cmd /k
:WEB2
CLS
call ssh user#xxx.xxx.xxx.xxx
cmd /k
I'm trying to automate a script that copies a file from my local server to a remote server on the command line. I've done the research on scp and know how to copy the file to the remote server, but then I want to append that file to another.
This is my code:
scp ~/file.txt user#host:
ssh user#host cat file.txt >> other_file.txt
When I enter everything into the command line manually as such, everything works fine:
scp ~/file.txt user#host:
ssh user#host
cat file.txt >> other_file.txt
But when I run the script, only the file is copied, not appended to the end of other_file.txt. Help?
The second line of your code should be
ssh user#host "cat file.txt >> other_file.txt"
Three important points:
You don't want your local shell to interpret >> in any way (which it does if it's unquoted)
There is a remote shell which will interpret >> in the command correctly.
Final arguments to ssh are "joined" to form a command, not carried into an argv array as they are. It may be convenient but it also may lead to confusion or bugs: ssh cat "$MYFILE" and ssh "cat '$MYFILE'" both work in a common use case, but they both break for different values of $MYFILE.
You need to enclose the command to be run on the remote host in quotes. Otherwise, the redirection is being done locally rather than remotely. Try this instead:
scp ~/file.txt user#host:
ssh user#host 'cat file.txt >> other_file.txt'
Try this:
$ cat file.txt| ssh hostname 'cat >> other_file.txt'