linux关机时候执行命令脚本或程序
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
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
支付宝扫一扫捐赠
支付宝扫一扫捐赠
微信公众号: 共鸣圈
欢迎讨论,邮件: 924948$qq.com 请把$改成@
QQ群:263132197
QQ: 924948