title: Run shutdown command inside bash script
body: <p>I'm trying to make an executable file (bash script) to show me a notification and shutdown my computer when a process is not found.</p>
  
  <p>I will run the script as a Startup Application and I'm using the <code>notify-send</code> and <code>shutdown</code> commands in this script.  </p>
  
  <p>The problem is:<br>
  (1) If I add <code>myfolder/myscript</code> to the Startup Applications list it can't run the <code>shutdown</code> command (root password is required for this)<br>
  (2) If I add the script <code>sudo myfolder/myscript</code> it can't show the notifications via <code>notify-send</code> application.</p>
  
  <p>I've already done a lot of searching around the internet and tried these steps:<br>
  (1) Added the script path or <code>/sbin/shutdown</code> to the sudores via <code>sudo visudo</code><br>
  (2) Added <code>su - $USER -c "DISPLAY=$DISPLAY DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$UID/bus</code> before <code>notify-send</code> command (I found some users reporting that root can't send notifications)`</p>
  
  <p>So... none of them worked. What I'm missing?
  What can be done to display notifications AND shutdown?</p>
  
  <p>Here is my code:</p>
  
  <pre><code>#!/bin/bash
  
  #Search for a specific process and sleep if it is found (removed for space saving)
  
  shut_time=$(date --date='10 minutes' +"%T")
  notify-send -t 600000 "WARNING:
  Program is not running.
  Shutting down in 10 minutes (scheduled for $shut_time)."
  
  #ALREADY TESTED BELLOW LINES (DON'T WORK)
  #su - $USER -c "DISPLAY=$DISPLAY DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$UID/bus notify-send -t 600000 'WARNING:
  #Program is not running.
  #Shutting down in 10 minutes.'"
  
  sudo /sbin/shutdown -h +10 #Tried with our without sudo
  </code></pre>
  
  <p>I'm running MX Linux 18 (xfce, Debian based).  </p>