<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="FeedCreator 1.8" -->
<?xml-stylesheet href="https://www.ainw.org/wiki/lib/exe/css.php?s=feed" type="text/css"?>
<rss version="2.0">
    <channel xmlns:g="http://base.google.com/ns/1.0">
        <title>Mon wiki - pele_mele:stack_exchange:superuser</title>
        <description></description>
        <link>https://www.ainw.org/wiki/</link>
        <lastBuildDate>Sat, 09 May 2026 06:07:06 +0000</lastBuildDate>
        <generator>FeedCreator 1.8</generator>
        <image>
            <url>https://www.ainw.org/wiki/lib/exe/fetch.php?media=wiki:dokuwiki.svg</url>
            <title>Mon wiki</title>
            <link>https://www.ainw.org/wiki/</link>
        </image>
        <item>
            <title>1225022</title>
            <link>https://www.ainw.org/wiki/doku.php?id=pele_mele:stack_exchange:superuser:1225022&amp;rev=1732362926&amp;do=diff</link>
            <description>
&lt;h1 class=&quot;sectionedit1&quot; id=&quot;send_notification_from_systemd&quot;&gt;Send notification from systemd&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;p&gt;
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.
&lt;/p&gt;

&lt;p&gt;
Here is the important part of the script:
&lt;/p&gt;
&lt;pre class=&quot;code bash&quot;&gt;&lt;span class=&quot;co0&quot;&gt;#!/bin/bash&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;re2&quot;&gt;USER&lt;/span&gt;=&lt;span class=&quot;sy0&quot;&gt;&amp;lt;&lt;/span&gt;username&lt;span class=&quot;sy0&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;re2&quot;&gt;USERID&lt;/span&gt;=&lt;span class=&quot;sy0&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;id&lt;/span&gt; &lt;span class=&quot;re5&quot;&gt;-u&lt;/span&gt; &lt;span class=&quot;re1&quot;&gt;$USER&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;`&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw2&quot;&gt;sudo&lt;/span&gt; &lt;span class=&quot;re5&quot;&gt;-u&lt;/span&gt; &lt;span class=&quot;re1&quot;&gt;$USER&lt;/span&gt; &lt;span class=&quot;kw2&quot;&gt;bash&lt;/span&gt; &lt;span class=&quot;re5&quot;&gt;-c&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/&lt;span class=&quot;es2&quot;&gt;$USERID&lt;/span&gt;/bus notify-send -t 5000 -u normal -i /usr/share/icons/Adwaita/32x32/devices/drive-removable-media.png &#039;Ah! the element of surprise&#039;&amp;quot;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;
When I run it from my terminal, it works well.
&lt;/p&gt;

&lt;p&gt;
I&amp;#039;ve created a service file in &lt;code&gt;/etc/systemd/system&lt;/code&gt; with the following content:
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;[Unit]
Description=Test notification
Requires=home.mount
After=home.mount

[Service]
ExecStart=/home/alexis/Personnalisation/Scripts/test.notification.sh
Type=oneshot

[Install]
WantedBy=graphical.target&lt;/pre&gt;

&lt;p&gt;
When I run it through &lt;code&gt;sudo systemctl start test.notification&lt;/code&gt;, it works well.
&lt;/p&gt;

&lt;p&gt;
The problem arise when systemd runs after I run &lt;code&gt;systemd enable test.notification&lt;/code&gt;.
&lt;/p&gt;

&lt;p&gt;
If I add other things in the script, they are done.
&lt;/p&gt;

&lt;p&gt;
Is my service description wrong? Is my notification instruction missing something?
&lt;/p&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;plugin_wrap_start&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;&amp;quot;,&amp;quot;secid&amp;quot;:2,&amp;quot;range&amp;quot;:&amp;quot;0-&amp;quot;} --&gt;&lt;div class=&quot;wrap_help plugin_wrap&quot;&gt;
&lt;p&gt;
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&amp;#039;ve change &lt;code&gt;bash&lt;/code&gt; by &lt;code&gt;/bin/bash&lt;/code&gt;.
&lt;/p&gt;

&lt;p&gt;
I&amp;#039;ve found out what was wrong by running the script without the environment:
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;env -i /path/to/script&lt;/pre&gt;

&lt;p&gt;
It returned the following error:
&lt;/p&gt;
&lt;blockquote&gt;&lt;div class=&quot;no&quot;&gt;
 sudo: bash: command not found&lt;/div&gt;&lt;/blockquote&gt;

&lt;p&gt;
This error is self explanatory and helped me find the problem.
&lt;/p&gt;
&lt;/div&gt;&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;plugin_wrap_end&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;&amp;quot;,&amp;quot;secid&amp;quot;:3,&amp;quot;range&amp;quot;:&amp;quot;0-&amp;quot;} --&gt;&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;plugin_wrap_start&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;&amp;quot;,&amp;quot;secid&amp;quot;:4,&amp;quot;range&amp;quot;:&amp;quot;0-&amp;quot;} --&gt;&lt;div class=&quot;wrap_info plugin_wrap&quot;&gt;
&lt;p&gt;
&lt;a href=&quot;https://superuser.com/questions/1225022/send-notification-from-systemd&quot; class=&quot;urlextern&quot; title=&quot;https://superuser.com/questions/1225022/send-notification-from-systemd&quot; rel=&quot;ugc nofollow&quot;&gt;Send notification from systemd - Super User&lt;/a&gt;
&lt;/p&gt;
&lt;/div&gt;&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;plugin_wrap_end&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;&amp;quot;,&amp;quot;secid&amp;quot;:5,&amp;quot;range&amp;quot;:&amp;quot;0-&amp;quot;} --&gt;
&lt;/div&gt;
</description>
            <author>anonymous@undisclosed.example.com (Anonymous)</author>
            <pubDate>Sat, 23 Nov 2024 11:55:26 +0000</pubDate>
        </item>
    </channel>
</rss>
