i have tried to run the script before shutdown using systemd but its not working . I have created the following service:
[Unit]
Description=test
Before=shutdown.target
[Service]
Type=oneshot
ExecStart=/bin/true
ExecStop=/usr/local/bin/test.sh
RemainAfterExit=yes
TimeoutSec=300
[Install]
WantedBy=multi-user.target
In script, I just remove the file.