title: How to debug exec script for collectd
body: <p>I wrote a little script to collect the power state (standby, actice) of my disk.
  It is based on this script: <a href="https://github.com/collectd/collectd/blob/master/contrib/exec-smartctl" rel="nofollow noreferrer">https://github.com/collectd/collectd/blob/master/contrib/exec-smartctl</a></p>
  
  <p><code>/usr/share/collectd/exec_hddpwrmode.sh</code></p>
  
  <pre><code>#!/bin/bash
  HOSTNAME="${COLLECTD_HOSTNAME:-$(hostname -f)}"
  INTERVAL="${COLLECTD_INTERVAL:-60}"
  
  while sleep "$INTERVAL"
  do
    for disk in sda sdb sdc sdd sde sdf
    do
      STATE=$(sudo smartctl -i -n standby /dev/$disk | grep -e "Device is in STANDBY mode" -e "Power mode is:    ACTIVE or IDLE" 2&gt;/dev/null)
      if [ "$STATE" = "Device is in STANDBY mode, exit(2)" ]
        then
          # STANBY
          VALUE="0"
        else
          if [ "$STATE" = "Power mode is:    ACTIVE or IDLE" ]
            then
              # ACTIVE or IDLE
              VALUE="1"
            else
              # ERROR
              VALUE="U"
          fi
      fi
      echo "PUTVAL $HOSTNAME/disk-$disk/disk-state interval=$INTERVAL N:$VALUE" | tee -a /tmp/hddpwrstate.log
    done
  done
  </code></pre>
  
  <p>The output in <code>/tmp/hddpwrstate.log</code>looks good.</p>
  
  <pre><code>PUTVAL magneto/exec-smart/pwrstate_sdf interval=10.000 N:0
  PUTVAL magneto/exec-smart/pwrstate_sda interval=10.000 N:0
  PUTVAL magneto/exec-smart/pwrstate_sdb interval=10.000 N:1
  PUTVAL magneto/exec-smart/pwrstate_sdc interval=10.000 N:0
  PUTVAL magneto/exec-smart/pwrstate_sdd interval=10.000 N:0
  PUTVAL magneto/exec-smart/pwrstate_sde interval=10.000 N:0
  PUTVAL magneto/exec-smart/pwrstate_sdf interval=10.000 N:0
  </code></pre>
  
  <p>That means I have no permission issue (the script needs to be run by a user that can use sudo).
  And it is executed by collectd</p>
  
  <p>But I get no new rrd-files in <code>/var/lib/collectd/rrd/&lt;hostname&gt;</code> or new measurements in my InfluxDB.</p>
  
  <pre><code>&gt; show measurements
  name: measurements
  name
  ----
  cpu_value
  df_value
  disk_io_time
  disk_read
  disk_value
  disk_weighted_io_time
  disk_write
  entropy_value
  interface_rx
  interface_tx
  irq_value
  load_longterm
  load_midterm
  load_shortterm
  memory_value
  processes_value
  rrdcached_value
  swap_value
  uptime_value
  users_value
  </code></pre>
  
  <p>I tried activating debug.</p>
  
  <pre><code>&lt;Plugin syslog&gt;
    LogLevel debug
  &lt;/Plugin&gt;
  </code></pre>
  
  <p>But it does not help.</p>
  
  <pre><code>Nov 19 12:13:12 magneto collectd[30028]: Exiting normally.
  Nov 19 12:13:12 magneto collectd[30028]: collectd: Stopping 5 read threads.
  Nov 19 12:13:12 magneto collectd[30028]: exec plugin: Sent SIGTERM to 30042
  Nov 19 12:13:12 magneto collectd[30028]: collectd: Stopping 5 write threads.
  Nov 19 12:13:13 magneto collectd[31752]: Stopping statistics collection and monitoring daemon: collectd.
  Nov 19 12:13:13 magneto collectd[31767]: syslog: invalid loglevel [debug] defaulting to 'info'
  Nov 19 12:13:13 magneto collectd[31768]: syslog: invalid loglevel [debug] defaulting to 'info'
  Nov 19 12:13:13 magneto collectd[31769]: Initialization complete, entering read-loop.
  Nov 19 12:13:13 magneto collectd[31764]: Starting statistics collection and monitoring daemon: collectd.
  </code></pre>
  
  <p>So, why does my script not work?
  Is there something wrong?
  Or how can I debug to find the issue myself?</p>
  
  <p>My system: Debian 8 with OpenMediaVault.</p>