I keep a ton of SSH sessions open to various servers on my work desktop, and sometimes I can't remember where I put ther terminal with the session. Here's a script I wrote to help me find and raise a terminal that is connected to a server

    #!/bin/bash

    PID=$(ps ax | grep ssh | grep $1 | grep -v grep | awk '{print $1}' | head -n 1)
    if [ ! -z "$PID" ]
    then
        WID=$(cat /proc/$PID'/environ' | xargs --null --max-args=1 | grep WINDOWID | sed -e 's/^[^=]\+=//')
        wmctrl -i -a $WID
    else
        echo "No Process Found"
    fi
Comments on this page are closed.