避免重复执行的启动脚本

通过进程检测

一般用于避免 shell 脚本被重复执行

#!/bin/bash

if ! pgrep -f "start.sh" > /dev/null; then
    /tool/test/start.sh -v &
else
    echo "test Tools is running"
fi

AppImage 的程序也可实现

#!/bin/bash
WINDOW_CLASS="Chatbox"

if ! pgrep -f "Chatbox.AppImage" > /dev/null; then
    /home/eonun/Tools/Chatbox/Chatbox.AppImage --disable-gpu &
else
    wmctrl -x -a "$WINDOW_CLASS"
fi

通过窗口标题检测

#!/bin/bash

WINDOW_CLASS="$(wmctrl -l | grep '[B]urp Suite' | awk '{print $1}')"
echo "WINDOW_CLASS: $WINDOW_CLASS"

if [ -n "$WINDOW_CLASS" ]; then
    wmctrl -i -a "$WINDOW_CLASS"
else
    echo "Burp Suite window not found."
    /home/eonun/Tools/Penetest/BurpSuitePro/BurpSuitePro %U &
fi