#!/bin/bash
#######################################
#                                     #
#  Calculates disk I/O                #
#                                     #
#  PLEASE DO NOT EDIT THIS SCRIPT !   #
#                                     #
#######################################

if [ "$1" = "" ]; then
  echo -e "\n\e[31m  Can only be started from within conky!\e[m\n"
  exit
fi
if [ "$(which dstat)" = "" ]; then
  echo -e "\n'dtstat' not found! Will be installed now..\n"
  sudo apt install dstat
fi

tmp="./tempfiles/diskio"
tmpr="./tempfiles/diskio-read"
tmpw="./tempfiles/diskio-write"

rm -f "$tmp"
dstat --output $tmp --noheaders -r 1 2 > /dev/null

echo "$(cat "$tmp" | tail -n1 | awk -F"," '{print $1}' | awk -F"." '{print $1}')" > "$tmpr"
echo "$(cat "$tmp" | tail -n1 | awk -F"," '{print $2}' | awk -F"." '{print $1}')" > "$tmpw"
