Write a service file and place it in /etc/systemd/system/beforeshuttingdown.service

code:

[Unit]
Description=Run mycommand at shutdown
Requires=network.target
DefaultDependencies=no
Before=shutdown.target reboot.target
 
[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=/bin/true
ExecStop=mycommand [or path to script or program]

[Install]
WantedBy=multi-user.target

Your program or script must be executable. 脚本或者程序(mycommand)必须是可执行文件。

启用服务:

systemctl daemon-reload
systemctl enable beforeshuttingdown.service
systemctl start beforeshuttingdown.service

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-12
  • 2021-08-30
  • 2022-12-23
  • 2021-12-24
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-06-24
  • 2022-01-13
  • 2022-12-23
  • 2022-01-20
相关资源
相似解决方案