Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 5027

Advanced users • Re: Execute command at poweroff, not at reboot

$
0
0
OK, had another look at this, and found that the following works.

Code:

if [[ "$(systemctl list-jobs | grep reboot.target)" =~ "reboot.target" ]]then    echo "System is rebooting"elif [[ "$(systemctl list-jobs | grep poweroff.target)" =~ "poweroff.target" ]]then    echo "System is powering off"elif [[ "$(systemctl list-jobs | grep shutdown.target)" =~ "shutdown.target" ]]then    echo "System is shutting down"fi
The check for shutdown.target must be after others, b/c it is active along with reboot.target and poweroff.target.

Statistics: Posted by bls — Wed Feb 07, 2024 1:27 am



Viewing all articles
Browse latest Browse all 5027

Trending Articles