slish view tools/quota.sh @ rev 12

Add 2 small scripts to handle quota and signup
author Christophe Lincoln <pankso@slitaz.org>
date Tue Jan 28 21:38:25 2014 +0100 (2014-01-28)
parents
children
line source
1 #!/bin/sh
2 #
3 # Monitor SliSH home with inotifywait, alert user and delete last file.
4 #
5 . /lib/libtaz.sh
7 [ "$root" ] || root="/home/slish/chroot"
8 home="${root}/home"
9 people="$(dirname $root)/people"
10 logs="$(dirname $root)/logs"
11 activity="$logs/activity.log"
13 #trap "killall inotifywait" EXIT
14 debug "Monitoring: $home"
16 inotifywait -m -r \
17 -e modify -e create ${home} 2>/dev/null | while read path event file
18 do
19 user=$(echo $path | sed s"#${home}/##" | cut -d "/" -f 1)
20 size=$(du -sm ${home} | awk '{print $1}')
21 tty="$(who | grep ^${user} | awk '{print $2}')"
22 . ${people}/${user}/account.conf
23 QUOTA="20"
24 if [ "$size" -gt "$QUOTA" ]; then
25 activity="$logs/alert.log"
26 debug "Quota exceeded for: $user"
27 log "Quota exceeded for: $user"
28 echo "$(colorize 31 ALERT:) quota exceeded" > /dev/${tty}
29 debug "Removing: ${path}${file}"
30 rm -rf ${path}${file}
31 fi
32 done