If I echo into /dev/pts/N, in a terminal using SSH, will it
If I echo into /dev/pts/N, where pts/N is a terminal using SSH, will it send something to the server that SSH is connected to?
Code:
# In terminal 1, which is connected to /dev/pts/5, we ^.^ |
It's only sending to the PTS itself and not going over the SSH session to the remote server. Try the following. On the remote server:
Code:
cat >> /tmp/foo Code:
echo "largue monos" > /dev/pts/N Then back in the SSH session type something and then close the file with a ctrl-d Code:
bar |
I see.
Is there a way I can send something to an open SSH session without it being focused? Maybe a kind of keyboard event. |
Well, a bit of a kludge might be to run your SSH session inside a named tmux session and then use tmux to send to it.
Code:
tmux new-session -s foobar 'ssh -p 22 server.example.com' Code:
tmux send-keys -t foobar 'ls' C-m |
Yes, would be nice to explain what do you really want to achieve, probably there is a way...
|
Quote:
The situation is that my Internet provider silently kills SSH sessions if they are silent for 5 minutes - which is common for me (and everybody, I guess) to do. I created a Bash script to echo something every second until I press any key: Code:
#!/bin/bash With the "echo to the SSH session" idea, I plan to make something to "ping" each SSH session every 4 minutes. Something neutral like a chosen keypress (space, backspace, F3, ...) or (shift/ctrl/alt if they may send something without a second "normal" key being pressed while we hold them) or anything else that is good for what I usually run (id est, something that will not probably break whatever I usually run in those sessions). |
Quote:
I will (or I am, at the moment you read this sentence) quickly read about tmux... |
Do the sessions still get killed by the ISP if the client has ServerAliveInterval set or if the server has ClientAliveInterval set? Either of those should send a heartbeat over the connection. You can set ServerAliveInterval specific to particular hosts in ~/.ssh/config. See "man ssh_config" for details.
Alternately, if you run tmux on the remote host, the clock in the default configuration should update every few seconds and thus send a few packets. |
Quote:
Code:
ssh -t server.example.com 'tmux a || tmux' |
Quote:
Quote:
On the other hand, "GNU screen" is already installed there. May I send a keypress command to it, like you showed for tmux? Skimming through 'screen' manpage did not ring anything to me. |
You can also send keystrokes through screen. However, first I'd see if ServerAliveInterval does the job for you instead. You can test it this way:
Code:
ssh -o ServerAliveInterval=15 server.example.com |
Thank you very much for all your posts here, Turbocapitalist!
I will reopen one of the sessions I have now, calling ssh with that option, and not using my "stay alive" script. Hopefully it will be enough. (: I did not imagine that an SSH option could solve the problem because I use the same machine+OS+ssh I used a few years ago, when I had another provider - the problem never happened, even after hours without using an open SSH session. I assumed it should be something "not so common to make it the bad way, but not many customers would complain about" - and I did decide not to spend time calling support several times to solve that problem. I got around it as I could, as you all already know from my other posts here. |
in that case you may try to check logs to find the reason (on both client/server side).
|
Quote:
Something important to note, that I read in ssh_config man page, is that: Quote:
Code:
# Do not let SSH sessions die for a lack of attention |
Quote:
Code:
Host server1 server1.example.com |
All times are GMT -5. The time now is 01:03 AM. |