AW: [OpenAFS] Check free space on AFS share before login

Richter, Michael m.richter@tu-berlin.de
Thu, 2 Feb 2017 15:26:48 +0000


I got it working now. If someone wants it too:

This is the interesting part of the script:

~~~
# limit in kbyte
LIMIT=3D1000

uid=3D$(getent passwd "$PAM_USER" | cut -d ":" -f 3)
quota=3D$(vos examine "user.$uid" -format -noauth)
total=3D$(echo "$quota" | grep maxquota | awk '{print $2}')
usage=3D$(echo "$quota" | grep diskused | awk '{print $2}')
if [ $(($total - $usage)) -lt $LIMIT ]
then
        # quota nearly reached
        echo Sie haben weniger als $LIMIT KByte
        echo Speicher frei. Bitte melden Sie sich
        echo unter Windows an und entfernen Sie Daten
        echo von Laufwerk Z: um sich wieder unter
        echo Ubuntu anmelden zu k=F6nnen.
        exit 1
fi

exit 0
~~~

Is called by /etc/pam.d/lightdm:

~~~
auth    requisite       pam_exec.so stdout type=3Dauth /opt/check_afs_free.=
sh
~~~

And the second script notifies the user when he is logged in and the free s=
pace is nearly reached (mostly the same script):

~~~
uid=3D$(id -u)
quota=3D$(vos examine "user.$uid" -format -noauth)
total=3D$(echo "$quota" | grep maxquota | awk '{print $2}')
usage=3D$(echo "$quota" | grep diskused | awk '{print $2}')
if [ $(($total - $usage)) -lt $LIMIT ]
then
        # quota nearly reached
        # height doesn't work correct but it's ok
        # zenity is shorter but makes an extremly wide dialog
        yad --width=3D700 \
                --height=3D200 \
                --center \
                --image=3D"gtk-dialog-warning" \
                --button=3Dgtk-ok \
                --buttons-layout=3Dcenter \
                --title=3D"Speicher fast voll" \
                --text=3D"Sie haben weniger als $LIMIT KByte Speicher frei.=
 Wenn der Speicher voll ist, k=F6nnen Sie sich nicht mehr unter Ubuntu anme=
lden. Bitte entfernen Sie unn=F6tige Dateien aus Ihrem Pers=F6nlichen Ordne=
r."
fi
exit 0
~~~

Called after login via /etc/xdg/autostart/notify-afs-free.desktop

Thanks for your help!

--=20
Michael Richter

Technische Universit=E4t Berlin
Universit=E4tsbibliothek
IT-Service

Fasanenstra=DFe 88, 10623 Berlin
Telefon: +49 (0)30 314-76310
m.richter@tu-berlin.de

www.ub.tu-berlin.de


-----Urspr=FCngliche Nachricht-----
Von: Stephan Wiesand [mailto:stephan.wiesand@desy.de]=20
Gesendet: Donnerstag, 2. Februar 2017 14:46
An: openafs-info@openafs.org
Cc: Richter, Michael
Betreff: Re: [OpenAFS] Check free space on AFS share before login

Hmm, it should work in any case. The message can be suppressed with the -no=
auth option for vos.

> On 2 Feb 2017, at 14:42, Richter, Michael <m.richter@tu-berlin.de> wrote:
>=20
> OK, did so. But: running "vos examine" in a shell works. If I put the sam=
e line into a script and call this script on the same shell, it doesn't wor=
k and gives me this error:
>=20
> vsu_ClientInit: Could not get afs tokens, running unauthenticated.

--=20
Stephan Wiesand
DESY -DV-
Platanenallee 6
15738 Zeuthen, Germany