To execute a script on every shutdown with systemd, create a service file with the content:
(on-shutdown.service)
[Unit] Description=Will be executed on Shutdown [Service] Type=oneshot RemainAfterExit=true ExecStop=/usr/local/bin/youscript.sh [Install] WantedBy=multi-user.target
Put it inside the /etc/systemd/system folder, and enable it with:
systemctl deamon-reload systemctl enable on-shutdown.service --now