Monday, February 26, 2024
 Popular · Latest · Hot · Upcoming
3
rated 0 times [  3] [ 0]  / answers: 1 / hits: 1560  / 2 Years ago, tue, february 8, 2022, 5:57:02

I run a java application as a server on a EC2. But as I loose my ssh connection all console messages are also lost. When I redirect all messages to > my.log and then use tail -f my.log I dont get the e.printstacktrace messages. I wonder what I can do.



Is there something simple that I can do, to relogin to ssh, find out which console the java application is throwing out all the messages.



So instead of doing a java myapp.jar &, I now do a java myapp.jar, so that I dont loose any console messages.



The other question is, Is there a better command than > my.log that does not miss any message from my application, so that I can log, and do a tail -f my.log ?


More From » ssh

 Answers
0

I would use a terminal multiplexer - screen being the best known, and tmux being a more recent implementation of the idea. I use tmux, and would recommend you do to.



Basically tmux will run a terminal (or set of terminals) on a computer. If you run it on a remote server, you can disconnect from it without the terminal dying. Then when you login in again later you can reconnect, and see all the output you missed.



To start it the first time, just type



tmux


Then, when you want to disconnect, you do Ctrl-B d (ie press Ctrl-B, then release both keys, and then press d.



When you login again, you can run



tmux attach


and you will reconnect to tmux and see all the output that happened. Note that if you accidentally lose the ssh connection (say your network goes down), tmux will still be running, though it may think it is still attached to a connection. You can tell tmux to detach from the last connection and attach to your new connection by running



tmux attach -d


In fact, you can use the -d option all the time. On servers, I have this in my .bashrc



alias tt='tmux attach -d'


So when I login I can just type tt and reattach. You can go one step further if you want and integrate the command into an alias for ssh. I run a mail client inside tmux on a server, and I have a local alias:



alias maileo='ssh -t mail.example.org tmux attach -d'


This does ssh to the server and runs the command at the end - tmux attach -d The -t option ensures that a terminal is started - if a command is supplied then it is not run in a terminal by default. So now I can run maileo on a local command line and connect to the server, and the tmux session. When I disconnect from tmux, the ssh connection is also killed.



This shows how to use tmux for your specific use case, but tmux can do much more than this. This tmux tutorial will teach you a bit more, and there is plenty more out there.


[#36848] Wednesday, February 9, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
atetamme

Total Points: 11
Total Questions: 121
Total Answers: 109

Location: Puerto Rico
Member since Sun, Jun 27, 2021
3 Years ago
;