Last Updated or created 2023-02-14
I’m using a lot of terminals, spawning a new terminal and running ssh, without knowing if i still have a session running.
Lets see:
This was done using something like:
#!/bin/bash count=$(ps -ef | grep xterm | grep -v grep | wc -l) timestamp=$(date +%s) echo "$timestamp,$count" >> /var/local/terminallog
Later i made a script to push this information in Grafana
Now for the SSH part.
I’m jumping from machine to machine using ssh, sometime i loop back to a server i was already connected to .. this helps me to keep track
in ssh_config add SendEnv SSHTRAIL in sshd_config add AcceptEnv SSHTRAIL in /etc/profile export SSHTRAIL=$SSHTRAIL:$HOSTNAME restart sshd when you do this on all your machines you can get a trail of ssh using: echo $SSHTRAIL workstation:server1:server66:server1 I could change the prompt when a loop is detected echo $SSHTRAIL | sed -e 's/:/\n/g' | sort | uniq -c | grep -v 1 | ... | echo "WARNING: loop in ssh"