When I start long running jobs, I try do start them that way, so I can check on them (and their output in a screen logfile) from anywhere:
screen -L -Logfile "batch-xyzzy-221005a" -S "xyzzy1" bash job.sh
Now I can just check the log with grep or less, or reattach to it if some action is needed.
By the way another approach is of course to use VNC (e.g. some process started in an xterm at work you can access by opening your entire desktop at home.)
kitty probably has some abilities to do this easily from the shell, as it has all sorts of abilities to interact programmatically with the scrollback history.
How about starting tmux by default inside a terminal, rather than running the shell directly inside the terminal?
Of course, an ssh session would also need to start tmux.
Interesting. So far, my only ever use of disown was to decouple GUI apps that I launched from the terminal. I do that automatically now, as it's annoying when you forget, close the terminal, and a bunch of apps go away.
> The shell exits by default upon receipt of a SIGHUP. Before exiting, an interactive shell resends the SIGHUP to all jobs, running or stopped. [...] To prevent the shell from sending the SIGHUP signal to a particular job, it should be removed from the jobs table with the disown builtin (see Job Control Builtins) or marked to not receive SIGHUP using disown -h.
> If the huponexit shell option has been set with shopt (see The Shopt Builtin), Bash sends a SIGHUP to all jobs when an interactive login shell exits.
https://www.gnu.org/software/bash/manual/html_node/Signals.h...
nohup <gui-app> &
? $ reptyr 10330
Unable to attach to pid 10330: Operation not permitted
The kernel denied permission while attaching. If your uid matches
the target's, check the value of /proc/sys/kernel/yama/ptrace_scope.
For more information, see /etc/sysctl.d/10-ptrace.conf
$
I haven't (yet) looked into how to fix or work around this problem.# echo 0 > /proc/sys/kernel/yama/ptrace_scope
or permanently by editing the file /etc/sysctl.d/10-ptrace.conf
There are various ways to get ahead of this problem too if you ssh into a tmux session automatically. There are various ways to achieve this.
I didn't know about reptyr, it's very cool. There were times I wished this was possible, but whenever I searched for a solution I got "It's not possible". Oh well...
ssht() {
ssh -t $1 'tmux a || tmux'
} autossh -M 0 -t remote "tmux new-session -A -D -s $RANDOM$RANDOM$RANDOM$RANDOM"
with appropriate ServerAliveInterval and ServerAliveCountMax settings. It works somewhat nicely with dodgy ssh conncetions too. I'm aware of mosh, but this one even outlives when I put the laptop to sleep. Also mosh doesn't allow X forwarding, and I enable that for sharing the clipboard (yes, I'm aware of the security implications). And if I want to leave something long-running, I can just close the window and reattach later.Pretty cool use of ptrace.
In practice I have it via bash alias `tma` , not long command as described. Until I can't bring my .bashrc to particular server of course - there long one, may try your suggestion though
Remote pair coding made fun again!