Shutdown Script Issue

Because my GPD Pocket 3 loses sound upon resume-from-hibernation, I run a timed shutdown script:

#!/bin/bash
idletime=$((30*120*1000)) # 30 min in milliseconds
idle=0

while [ $idle -lt $idletime ];do
    idle=$(xprintidle)
    sleep 1
done
/home/jake/Scripts_Icons/Word_Shutdown
sleep 2
sudo shutdown -P now

Word_Shutdown Script:

#!/bin/bash
if test "$(wmctrl -l | grep -c "Microsoft Word" 2>&1)" -eq 1; then
    wmctrl -a "Microsoft Word"
    sleep .2
    xdotool keydown 0xffea + key 4
    sleep .2
    xdotool keyup 0xffea
    sleep .2
   xdotool key y
fi

Everything works fine except for logout. At the logout screen, the machine promptly shuts down unassisted. If I kill the above shutdown script before I logout, logout works appropriately.

For now, I run a keystroked logout script, which kills the shutdown script, then runs the logout command.

Any idea why my shutdown script is shutting down the device upon logout?

Thanks,
Jake

You have that running 2 seconds right after the logout script …

Thank you for your reply. The logout script (not listed above) simply kills the shutdown script, then logs out. But if I don’t run the logout script–meaning that the shutdown is still running as a process–logging out somehow invokes sudo shutdown -P now and I can’t figure out why.

I suppose I could abandon the whole thing and return to shallow idle (the Pocket 3 can’t resume with anything deeper) and wait to see if a kernel release will fix s2idle, etc for the Pocket 3. Right now, I’m at 5.18.