Hi gents,
after searching a script to massive set quota for users on HP-UX, i’ve found nothing, only people asking how to do it.
of course you have the ‘edquota’ command, which can copy a user’s quota template into another account, but this is not the best way.
so, i’ve wrote a little script to do the job, for all my NFS users.
this script will definitively not fit for an other person than me and my needs, but I think it can be a good basis.
As usually, if you need a specific version to fit your needs, and you d’ont know how to do it, I can help.
#!/bin/ksh -a # MUST BE RUN FROM THE MOUNTROOT OF THE FS # for example : from /nfsint1/export02 # USERS must be in the subdirectory users # for example : /nfsint1/export02/users V_TEMPFILE=/tmp/quotaset DEFS_QUOTA=50000 DEFH_QUOTA=55000 DEFS_INODE=5000 DEFH_INODE=5500 V_DATE=$(date +"%d-%m-%Y_%Hh%Mm%S") if [ -f "$1" ] then # Important cp /dev/null ${V_TEMPFILE} function fct_quotaset { echo "INFO: working on user $u_user" while read a FS b c d SQ e f HQ g h i SI j k HI do [ "$FS" != "$(pwd)" ] && { echo "$a $FS $b $c $d $SQ $e $f $HQ $g $h $i $SI $j $k $HI" >>${V_TEMPFILE} continue } softquota=$(echo $SQ |cut -d"," -f1) if [ "$softquota" = "0" ] then realuse=$(du -ks users/${u_user} |awk '{print $1}') if [ "$realuse" -le "$DEFS_QUOTA" ] then echo "INFO: ${u_user} uses ${realuse}ko space" cp $1 quota-bck/${u_user}.${V_DATE} softquota=$DEFS_QUOTA else echo "WARNING: ${u_user} exceeds the default QUOTA, can't set IT (${realuse}ko)" fi elif [ "$softquota" -gt "$DEFS_QUOTA" ] then echo "WARNING: the quota defined for $u_user exceeds the standard ($softquota > $DEFS_QUOTA)" fi hardquota=$(echo $HQ |cut -d")" -f1) [ "$hardquota" = "0" ] && { [ "$realuse" -le "$DEFS_QUOTA" ] && { hardquota=$DEFH_QUOTA } } softinode=$(echo $SI |cut -d"," -f1) [ "$softinode" = "0" ] && { softinode=$DEFS_INODE } hardinode=$(echo $HI |cut -d")" -f1) [ "$hardinode" = "0" ] && { hardinode=$DEFH_INODE } echo "$a $FS $b $c $d ${softquota}, $e $f ${hardquota}) $g $h $i ${softinode}, $j $k ${hardinode})" >>${V_TEMPFILE} done < $1 cat ${V_TEMPFILE} > quota-bck/${u_user}.new cat ${V_TEMPFILE} > $1 } fct_quotaset $1 else # WANT a backup [ ! -d "quota-bck" ] && { mkdir quota-bck } [ ! -f "quotas" ] && { echo "ERROR: no quotas file found !" exit 1 } [ ! -d "users" ] && { echo "ERROR: no 'users' dir found !" exit 1 } for v_user in users/* do [ ! -d "$v_user" ] && continue u_user="${v_user##*/}" [ "$u_user" = "TT_DB" ] && continue id ${u_user} >/dev/null 2>&1 [ "$?" -ne "0" ] && { echo "ERROR: user $u_user does not exists in this system, you should maybe delete the '$v_user' directory" continue } EDITOR="${0}" edquota $u_user done fi
– you can set the default quota in the header
– If an account has a quota greater than the standard, It will be reported (be not modified)
– If an account has no quota defined AND exceeds the standard, It will be reported (be not modified)
– If an account has no quota defined and uses normal space, quota will be set
PS:
the quota utilization should be check through the command ‘quota -v’ to obtain the best actual quota utilization.