admin scripts
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.6 KiB

  1. #!/bin/bash
  2. #Globals
  3. device='/dev/sda1'
  4. ndevice='/dev/sda1'
  5. #Set New Quota's for ordinary users
  6. new_bquota=2000000
  7. new_blimit=2100000
  8. new_fquota=1800000
  9. new_flimit=2000000
  10. #Get users start for loop
  11. for user in $(getent passwd | awk -F : '{print $1}'); do
  12. #Check for actual users with quotas
  13. if [ "$(quota -lu "$user" | grep -c $device)" -eq "1" ]; then
  14. old_bquota=$(quota -lu "$user" | grep $device | awk '{print $3}')
  15. old_blimit=$(quota -lu "$user" | grep $device | awk '{print $4}')
  16. old_fquota=$(quota -lu "$user" | grep $device | awk '{print $6}')
  17. old_flimit=$(quota -lu "$user" | grep $device | awk '{print $7}')
  18. #Compare old v new and setup values for set quota:
  19. #Block Quota
  20. if [ "$old_bquota" -lt $new_bquota ]; then
  21. bquota=$new_bquota
  22. else
  23. bquota=$old_bquota
  24. fi
  25. #Block Limit
  26. if [ "$old_blimit" -lt $new_blimit ]; then
  27. blimit=$new_blimit
  28. else
  29. blimit=$old_blimit
  30. fi
  31. #File Quota
  32. if [ "$old_fquota" -lt $new_fquota ]; then
  33. fquota=$new_fquota
  34. else
  35. fquota=$old_fquota
  36. fi
  37. #File Limit
  38. if [ "$old_flimit" -lt $new_flimit ]; then
  39. flimit=$new_flimit
  40. else
  41. flimit=$old_flimit
  42. fi
  43. #Set the users Quota on New Device
  44. setquota -u "$user" "$bquota" "$blimit" "$fquota" "$flimit" "$ndevice"
  45. #Testing:
  46. echo User: "$user"
  47. echo -e "Old Quota: $device\t$old_bquota\t$old_blimit\t$old_fquota\t$old_flimit"
  48. echo -e "New Quota: $ndevice\t$bquota\t$blimit\t$fquota\t$flimit"
  49. else
  50. echo "User $user has no $device quota"
  51. echo
  52. fi
  53. echo ----------------------------------------------------------------------
  54. done