pele_mele:stack_exchange:superuser:1225022
Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédente | |||
pele_mele:stack_exchange:superuser:1225022 [2024/11/23 03:55] – supprimée - modification externe (Date inconnue) 127.0.0.1 | pele_mele:stack_exchange:superuser:1225022 [2024/11/23 03:55] (Version actuelle) – ↷ Page déplacée et renommée de pele_mele:stack_exchange:superuser-1225022 à pele_mele:stack_exchange:superuser:1225022 alexis | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
+ | ====== Send notification from systemd ====== | ||
+ | |||
+ | |||
+ | At the end of a script I wrote, I want to send a notification to know when it ends. The content of the script is not important except the notification part. | ||
+ | |||
+ | Here is the important part of the script: | ||
+ | |||
+ | <code bash> | ||
+ | #!/bin/bash | ||
+ | |||
+ | USER=< | ||
+ | USERID=`id -u $USER` | ||
+ | |||
+ | sudo -u $USER bash -c " | ||
+ | </ | ||
+ | When I run it from my terminal, it works well. | ||
+ | |||
+ | I've created a service file in ''/ | ||
+ | < | ||
+ | [Unit] | ||
+ | Description=Test notification | ||
+ | Requires=home.mount | ||
+ | After=home.mount | ||
+ | |||
+ | [Service] | ||
+ | ExecStart=/ | ||
+ | Type=oneshot | ||
+ | |||
+ | [Install] | ||
+ | WantedBy=graphical.target | ||
+ | </ | ||
+ | When I run it through '' | ||
+ | |||
+ | The problem arise when systemd runs after I run '' | ||
+ | |||
+ | If I add other things in the script, they are done. | ||
+ | |||
+ | Is my service description wrong? Is my notification instruction missing something? | ||
+ | |||
+ | <WRAP help> | ||
+ | The problem is that systemd runs with a minimal environment and not all envvar are known during the script execution. To make it work, I've change '' | ||
+ | |||
+ | I've found out what was wrong by running the script without the environment: | ||
+ | |||
+ | < | ||
+ | env -i / | ||
+ | </ | ||
+ | It returned the following error: | ||
+ | |||
+ | > sudo: bash: command not found | ||
+ | |||
+ | This error is self explanatory and helped me find the problem. | ||
+ | </ | ||
+ | <WRAP info> | ||
+ | [[https:// | ||
+ | </ | ||