You are not logged in.

#1 2010-06-06 20:19:26

demian
Member
From: Frankfurt, Germany
Registered: 2009-05-06
Posts: 709

correct btrfs partition size in conky

I switched to btrfs today and noticed that conky doesn't show the correct size for my btrfs partitions.

So, i wrote a script to do that:

#!/bin/bash
# ~/.scripts/btrfs-size.sh
# use btrfs-show to print correct space estimates in conky
#

[[ $(id -u) -ne 0 ]] && echo "err, need root permissions" && exit 1

if [[ $1 = root ]];then
  device=/dev/sda3
elif [[ $1 = home ]];then
  device=/dev/sda5
elif [[ $1 = daten ]];then
  device=/dev/sdb1
fi

used=$(btrfs-show $device | grep Total | awk '{print $7}' | tr -d MKGB)
total=$(btrfs-show $device | grep path | awk '{print $4}' | tr -d MKGB)
unit=$(btrfs-show $device | grep Total | awk -F'[0-9]' '{print $NF}')

echo $(calc ${total}-${used}) $unit

Adjust the $1 part and call the script in conky via

 ${exec sudo /path/to/btrfs-size.sh home}${color}

(add a NOPASSWD entry for btrfs-size.sh via visudo).

The script (resp. btrfs-show) needs root access and depends on "calc" for the calculation, so it's obviously not very well written. Feel free to improve smile.

Regards,
demian

Last edited by demian (2010-06-07 12:25:30)


no place like /home
github

Offline

#2 2010-06-06 22:38:14

Zariel
Member
Registered: 2008-10-07
Posts: 446

Re: correct btrfs partition size in conky

instead of using calc cant you just use

echo $((${total}-${used})) $unit

?

Offline

#3 2010-06-06 22:49:53

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: correct btrfs partition size in conky

bash cries about the decimals. You've gotta outsource the work to awk or bc.

btrfs filesystem show /dev/sdd1 | awk '/\ *devid/{print $4 - $6}' | tr -d KMGB

My awk-fu isn't good enough to split off the units here...

Offline

Board footer

Powered by FluxBB