bash script with kdialog not running from cron
<p>I am trying to run a bash script from cron, but nothing seems to work.</p>

<p>Script:</p>

<pre><code>#!/bin/sh
printf '%s' $(date) '_END' &gt;&gt; battery_log.txt
export DISPLAY=:0
kdialog --msgbox "$(upower -i /org/freedesktop/UPower/devices/battery_BAT0| grep -E "state|to\ full|percentage")"
</code></pre>

<p>crontab (as sudo):</p>

<pre><code>SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/home/king/Scripts
#
# m h  dom mon dow   command
  * *   *   *   * bash /home/king/Scripts/my_battery_script
</code></pre>

<p>I have checked to make sure:</p>

<pre><code>the script is executable
root user owns the script
I can run the script from within a shell using ./my_battery_script
I can run other bash scripts from within cron (I created a test script that wrote to a text file). Worked fine
kdelibs-full is installed
</code></pre>

<p>Why wont this script run?</p>

<p><strong>Edit: More details</strong></p>

<p><li>Running on Linux Mint 17.3</p>

<p><li>kernel: 3.19.0-32-generic</p>

<p><li>what I expect to happen: when timer fires in cron it launches the script (as root). The script uses its own display (not sure of the term) based on the DISPLAY variable (or so I read on other forums) to display a battery message</p>

<hr>

<p>Logs from the script's actual execution follow:</p>

<pre><code>++ date 
+ printf %s Mon Jan 11 22:29:01 EST 2016 _END 
MonJan1122:29:01EST2016_END+ export DISPLAY=:0 
+ DISPLAY=:0 
++ upower -i /org/freedesktop/UPower/devices/battery_BAT0 
++ grep -E 'state|to\ full|percentage' 
++ cat /sys/class/thermal/thermal_zone0/temp 
++ awk '{print "deg C: "$1/1000}' 
+ /usr/bin/kdialog --msgbox ' state: discharging 
percentage: 58% \n cpu temp: deg C: 44.5' 
No protocol specified 
kdialog: cannot connect to X server :0
</code></pre>