fcrontabから送信された通知に通知は表示されません。

fcrontabから送信された通知に通知は表示されません。

そのリンクへの参照が失敗しました。ほとんどはUbuntu、GNOME、Cronの構文に固有のようです。

  1. https://askubuntu.com/questions/298608/notify-send-doesnt-work-from-crontab/346580#346580
  2. https://stackoverflow.com/questions/16519673/cron-with-notify-send
  3. Linux Mintでバッテリーが少なくなったときにどのように通知できますか?

ディスプレイ、dbus、フルコマンドパスをエクスポートします。

dwmを使用してArch Linuxを実行します。 fcron と fcrontab -e を使用します。

スケジュールされたタスクのリスト

@ 5s /usr/local/shsc/battlow

スクリプトを明示的に呼び出すと、期待どおりに動作します(/usr/shsc/battlow)。

スクリプト

#!/bin/sh

export DISPLAY=:0

battery_level=`acpi -b | grep -P -o '[0-9]+(?=%)'`
if [ $battery_level -le 100 ]; then
    notify-send "Battery low" "Battery level is ${battery_level}%!"
fi

を使用または使用せずに試しましたexport DISPLAY=:0

ディスプレイの確認

$ echo $DISPLAY
:0
# systemctl status fcron
● fcron.service - fcron periodical command scheduler
     Loaded: loaded (/usr/lib/systemd/system/fcron.service; enabled; vendor preset: disabled)
     Active: active (running) since Tue 2021-05-18 08:36:13 MST; 12min ago
   Main PID: 8778 (fcron)
      Tasks: 1 (limit: 18916)
     Memory: 2.3M
        CPU: 3.182s
     CGroup: /system.slice/fcron.service
             └─8778 /usr/bin/fcron -b

May 18 08:48:08 bar fcron[11367]: Job '/usr/local/shsc/battlow' started for user foo (pid 11372)
May 18 08:48:08 bar fcron[11367]: Job '/usr/local/shsc/battlow' completed
May 18 08:48:13 bar fcron[11383]: Job '/usr/local/shsc/battlow' started for user foo (pid 11388)
May 18 08:48:13 bar fcron[11383]: Job '/usr/local/shsc/battlow' completed

ベストアンサー1

おすすめ記事