Skip to content

Instantly share code, notes, and snippets.

@RafaelSchridi
Last active April 21, 2018 23:07
Show Gist options
  • Select an option

  • Save RafaelSchridi/0bd08fb8b75f97ca01f95448cb2000e4 to your computer and use it in GitHub Desktop.

Select an option

Save RafaelSchridi/0bd08fb8b75f97ca01f95448cb2000e4 to your computer and use it in GitHub Desktop.
Samba dfree for ZFS & non-ZFS on Ubuntu 16.04
#!/bin/bash
# File: /usr/local/bin/dfree 0755
CUR_PATH=$PWD
FILESYSTEM=$(df -PT $CUR_PATH | tail -1 | awk '{print $2}')
if [ $FILESYSTEM = 'zfs' ]; then
USED=$((`sudo zfs get -o value -Hp used $CUR_PATH`)) > /dev/null
AVAIL=$((`sudo zfs get -o value -Hp available $CUR_PATH`)) > /dev/null
AVAIL_KB=$(expr $AVAIL / 1024)
TOTAL_KB=$(expr $USED / 1024 + $AVAIL / 1024)
echo $TOTAL_KB $AVAIL_KB
else
df $CUR_PATH | tail -1 | awk '{print $2" "$4}'
fi
# File: /etc/sudoers.d/zfs 0440
# This is a prexisting file from the ZFS installtion. Just uncomment line 11-13 and 20 and remove ", \" from line 13
# If you system doesn't have this file you can just create it.
## Allow read-only ZoL commands to be called through sudo
## without a password. Remove the first '#' column to enable.
##
## CAUTION: Any syntax error introduced here will break sudo.
##
## Cmnd alias specification
Cmnd_Alias C_ZFS = \
/sbin/zfs "", /sbin/zfs help *, \
/sbin/zfs get, /sbin/zfs get *
## /sbin/zfs list, /sbin/zfs list *, \
## /sbin/zpool "", /sbin/zpool help *, \
## /sbin/zpool iostat, /sbin/zpool iostat *, \
## /sbin/zpool list, /sbin/zpool list *, \
## /sbin/zpool status, /sbin/zpool status *, \
## /sbin/zpool upgrade, /sbin/zpool upgrade -v
## allow any user to use basic read-only ZFS commands
ALL ALL = (root) NOPASSWD: C_ZFS
@RafaelSchridi
Copy link
Author

Tried to use
https://gist.github.com/steveh/7356e2ba93af5869f385#file-usr-local-bin-dfree-sh-L12
and
https://gist.github.com/umito/9198097

But they were just not working for me until i discovered /etc/sudoers.d/zfs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment