Score:0

shutdown and systemd service

eg flag

At 5am cron runs shutdown, systemd executed /home/myuser/bin/mailme-shutdown.sh and my pc poweroff. When I startup the pc an email coming to me. The email is the script (mailme-shutodown.sh) executed before I powered up the pc. Any idea to send email before pc shutdown? I use local postfix with external smtp service.

cat /etc/crontab
00 05   * * *   root    /sbin/shutdown -h now


[Unit]
Description=Run command at shutdown
Requires=network.target
Before=shutdown.target reboot.target halt.target

[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=/home/myuser/bin/mailme-startup.sh
ExecStop=/home/myuser/bin/mailme-shutdown.sh
User=myuser

[Install]
#WantedBy=multi-user.target
WantedBy=halt.target reboot.target shutdown.target

cat mailme-shutdown.sh

[...]
[email protected]
echo "body" | mail -s "test" "$email"
[...]
Score:-1
lk flag

Maybe you should check if email was sent, and if current mail queue is empty then shutdown. How to verify if an email was successfully sent by postfix?

Pol Hallen avatar
eg flag
how. how tell shutdown that queue is empty?
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.