systemd-timerから呼び出すシェルスクリプトからメールが飛ばない

systemd

systemd-timerから呼び出すシェルスクリプトからメールが飛ばないので原因を調べています.
なお,そのシェルを手で動かすとちゃんとメールが送信されることは確認しています.
また,setenforce 0としても動作しないし,SELinux関連のエラーも出ていません.

利用しているシェルは以下の通りです.

#!/bin/sh
DATE=`date +%Y%m%d%H%M`
echo test-mail | /usr/bin/mailx -s "myip(jp) ${DATE}" yuuji.ohtsu@gmail.com

2022/1/10
https://unix.stackexchange.com/questions/314329/mailx-not-sending-email-when-run-as-a-systemd-service
より(正確には上記URLをgoogle翻訳したものより.検索キーは”systemd timer mailx”)

echo test-mail | /usr/bin/mailx -Ssendwait -s "myip(jp) ${DATE}" yuuji.ohtsu@gmail.com

というように-Ssendwaitオプションをつけることによりメールが送信できるようになりました.

ちなみに,service,timerファイルは,

# cat sendmyip.timer
[Unit]
Description=Run sendmyip.service at every 3 hours
#Description=Run sendmyip.service at every hour

[Timer]
#OnCalendar=*-*-* *:*:00
OnCalendar=*-*-* 3,9,15,21:15:00
Unit=sendmyip.service

[Install]
WantedBy=timers.target
# cat sendmyip.service
[Unit]
Description=IP address notification

[Service]
Type=oneshot
ExecStart=/usr/bin/sh -c '/usr/local/libexec/send-myip.sh'

2022/1/10 https://wiki.archlinux.jp/index.php/Systemd/%E3%82%BF%E3%82%A4%E3%83%9E%E3%83%BC

にも記載がありました.

コメント

タイトルとURLをコピーしました