[SOLVED] If I echo into /dev/pts/N, in a terminal using SSH, will it
Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
# log into a server with SSH and leave it open:
$ ssh me@server
Password:
Welcome to server!
$
# Now, in terminal 2, connected to other /dev/pts/N
# in the local machine, I do the command:
$ echo 'Vamos brincar!' > /dev/pts/5
# I can see "Vamos brincar!" written in terminal 1, but
# I need to know: did it send something to server? Can I
# do that? How?
#
I also do not know how I would test and check that myself. If you know how, please say it. It will also solve this thread.
Yes, would be nice to explain what do you really want to achieve, probably there is a way...
My problem is not too hard. I have been "not really solving" it with some "tricks".
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
if [ -t 0 ]; then
stty -echo -icanon -icrnl time 0 min 0;
fi
count=0
keypress=''
while [ "$keypress" = "" ]; do
let count+=1
echo -ne $count'\r'
sleep 1
keypress="`cat -v`"
done
# These echoes clean a few lines and move the
# cursor up and back to make this script more
# invisible after it finishes
echo -en "\r\033[0K"
echo -en "\r\033[1A"
echo -en "\r\033[0K"
echo -en "\r\033[1A"
echo -en "\r\033[0K"
if [ -t 0 ]; then
stty sane;
fi
exit 0
I call this script from the command line, if I know I will leave an SSH session open for a few minutes (I did this in two sessions to write this post). I also call it from remote Makefiles to give me time to think about messages it may output. I still lose some connections when I think or do anything eventual away from the SSH sessions - which make me lose, for example, my Vim sessions' undo/redo actions for all open files.
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).
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.
Nice! In the first tmux command, may I use the SSH session like I would do calling SSH directly?
Yes, but you'd get far more advantage out of it by running it on the remote host instead.
Code:
ssh -t server.example.com 'tmux a || tmux'
That way if the connection does drop, it will connect to the old session in progress. But as mentioned above it may end up preventing the ISP from dropping the connection.
[...] a software application that can be used to multiplex several virtual consoles, allowing a user to access multiple separate terminal sessions inside a single terminal window or remote terminal session.
I will try to compile and locally install tmux in that server (for my user only, I have no admin access there). Seems a nice idea.
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.
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.
Now I have created a local ~/.ssh/config file with this:
Excellent. One thing to note with ~/.ssh/config is that since the client goes with the first match the directives must go from specific to general. It might not be so clear from the man page.
So server1 would get an interval of 29 seconds, but all others including server2 would get an interval of 31. But server1 and server2 can be reached either by their short names or full names.
Last edited by Turbocapitalist; 10-13-2017 at 11:04 AM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.