PID_FILE="/tmp/my-process.pid"
LOG_FILE="/tmp/my-process.log"
if [ -f "$PID_FILE" ]; then
local pid=$(cat "$PID_FILE" 2>/dev/null)
if [ -n "$pid" ] && kill -0 "$pid" 2>/dev/null; then
# echo "Already running (PID: $pid)"
nohup bash -c 'while true; do your-command; sleep 2; done' > "$LOG_FILE" 2>&1 &
noti --title MyTunnel --message "Started (PID: $(cat "$PID_FILE"))"
if [ ! -f "$PID_FILE" ]; then
local pid=$(cat "$PID_FILE" 2>/dev/null)
if kill -0 "$pid" 2>/dev/null; then
# echo "Stopped (PID: $pid)"
noti --title MyTunnel --message "Stopped (PID: $(cat "$PID_FILE"))"