Os: debian9.
touch /home/test/test.log
Existe uma função simples write-date em / etc / profile.
write-date(){
date >> /home/test/test.log
}
Crie um serviço em execução na reinicialização ou no desligamento.
vim /etc/systemd/system/test.service
[Unit]
Description=Run command at shutdown
Before=shutdown.target reboot.target
[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=/bin/bash /home/test/test.sh
[Install]
WantedBy=multi-user.target
A função simples data de gravação em /home/test/test.sh.
vim /home/test/test.sh
write-date
Ativar o test.service.
sudo systemctl enable test.service
Reinicie meu pc e verifique o log de test.service
sudo journalctl -u test
-- Logs begin at Thu 2018-02-01 00:03:59 HKT, end at Thu 2018-02-01 00:15:54 HKT. --
Feb 01 00:04:04 test systemd[1]: Starting Run command at shutdown...
Feb 01 00:04:05 test bash[438]: /home/test/test.sh: line 3: write-date: command not found
Feb 01 00:04:11 test systemd[1]: test.service: Main process exited, code=exited, status=127/n/a
Feb 01 00:04:11 test systemd[1]: Failed to start Run command at shutdown.
Feb 01 00:04:11 test systemd[1]: test.service: Unit entered failed state.
Feb 01 00:04:11 test systemd[1]: test.service: Failed with result 'exit-code'.
Como fazer com que o comando em / etc / profile seja encontrado?
cat -vet /home/test/test.sh
$
$
write-date$
$
$