linuxterminalcentos7tailmate-desktop

Check if a specific Linux Terminal is already open


We have a Server Startup Script that is calling a Mate Terminal (or GNOME Terminal - should not make a difference) as Part of the Server Startup process which is, in essence, tailing the Servers info log like that:

mate-terminal --title="APPSERVER LOG" --working-directory=$SERVER_LOCATION --hide-menubar -e "sh -c 'tail -f --retry -n 400 ./server.log'" &

Now as you might imagine, while developing one ends up with quite a couple of open terminals all tailing the same logfile at the end of the day, caused by several server restarts.

Now my quastion: Is it possible to somehow check the open terminals for a specific running command, a specific title or similar, to only open a new terminal if there is not already one tailing?

I checked the man pages of mate-terminal but could not find anything that does any Window Management.

We are running CentOS7 and MATE 1.12.1

cat /etc/*release
CentOS Linux release 7.2.1511 (Core) 

Solution

  • You could try to grep pid of mate like this:

    pgrep -d " " -f path/to/mate/terminal/binary
    

    And from there you decide if is necessary to open another, kill existing one, or whatever you want :)