LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Script to set different quota depending on User's Group ID (https://www.linuxquestions.org/questions/programming-9/script-to-set-different-quota-depending-on-users-group-id-214334/)

TechNett 08-06-2004 01:20 PM

Script to set different quota depending on User's Group ID
 
I am running RH9 and on a dedicated 40GB HDD, I have the /home folders.
I installed the quotas and it is working.

I need a Script to set different quotas depending on User's Group ID.

I have 700 users that belong to 9 different groups.

I am looking for a script to read the /etc/passwd and if the group ID is say 505, set the quota to 25MB, if the group ID is 506 set the quota to 30MB.

I am not sure how to go about writing this script.
Any help or guidance will be much appreciated!
Thanks,
Nett

Cedrik 08-06-2004 02:27 PM

you may also consider

id -g <username>

TechNett 08-06-2004 02:39 PM

In what context would I use 'id -g <username>?
How would that be written into a script?
Thanks!
Nett

TechNett 08-06-2004 02:44 PM

I was thinking the script should look somehting like this:

read file /etc/passwd
read line
if <group ID> = 505
then edquta 25MB

if <group ID> = 506
then edquta 20MB

if <group ID> = 507
then edquta 30MB

read next line
done

-----
I need help figureing how to write the commands.
Thanks,
Nett

Cedrik 08-06-2004 02:51 PM

Ok, say the starting group gid is : 500, and you add 5mb in each case, uou come from 25

Code:

#!/bin/bash

group_from=500
size_inccrement=5
quota_size=25

for group in $(cat /etc/group); do
  gid=$(echo $group | cut -d':' -f 3)
  name=$(echo $group | cut -d':' -f 1)
    if [ "$gid" = "$group_from" ] || [ "$gid" -gt "$group_from" ]; then
       
        # add the command to set quota here
        echo "set quota for group $name : $quota_size mb"
        let "quota_size+=$size_inccrement"
    fi
done


TechNett 08-09-2004 02:24 PM

Thank you so much, Cedrik, for your help. I was able to read your scipt and modify it to do what I needed. It is a lillte long, but it does the job.
Thanks again!
-Nett
This is what I came up with:



#!/bin/bash

group_501=501 #bg
group_502=502 #aid
group_503=503 #technology
group_504=504 #administrator
group_505=505 #teacher
group_506=506 #tempusers
group_507=507 #secretary
group_508=508 #loa
group_509=509 #miscscvs

quota_10=10
quota_20=20
quota_25=25
quota_30=30
quota_35=35


for group in $(cat /etc/passwd); do
gid=$(echo $group | cut -d ':' -f 4)
name=$(echo $group | cut -d ':' -f 1)

# group_501=501 #bg
if [ "$gid" = "$group_501" ] || [ "$gid" -gt "$group_501" ]; then
edquota -p exampleuser1 $name
echo "set quota for user $name : $quota_20 mb"
fi

# group_502=502 #aid
if [ "$gid" = "$group_502" ] || [ "$gid" -gt "$group_502" ]; then
edquota -p exampleuser2 $name
echo "set quota for user $name : $quota_20 mb"
fi

# group_504=504 #administrator
if [ "$gid" = "$group_504" ] || [ "$gid" -gt "$group_504" ]; then
edquota -p exampleuser4 $name
echo "set quota for user $name : $quota_25 mb"
fi

# group_505=505 #teacher
if [ "$gid" = "$group_505" ] || [ "$gid" -gt "$group_505" ]; then
edquota -p exampleuser5 $name
echo "set quota for user $name : $quota_25 mb"
fi

#group_506=506 #tempusers
if [ "$gid" = "$group_506" ] || [ "$gid" -gt "$group_506" ]; then
edquota -p exampleuser6 $name
echo "set quota for user $name : $quota_10 mb"
fi

#group_507=507 #secretary
if [ "$gid" = "$group_507" ] || [ "$gid" -gt "$group_507" ]; then
edquota -p exampleuser7 $name
echo "set quota for user $name : $quota_20 mb"
fi

#group_508=508 #loa
if [ "$gid" = "$group_508" ] || [ "$gid" -gt "$group_508" ]; then
edquota -p exampleuser8 $name
echo "set quota for user $name : $quota_25 mb"
fi

#group_509=509 #miscscvs
if [ "$gid" = "$group_509" ] || [ "$gid" -gt "$group_509" ]; then
edquota -p exampleuser9 $name
echo "set quota for user $name : $quota_10 mb"
fi


done

Cedrik 08-09-2004 02:45 PM

I am sure you will find a way to reduce it to say 7/8 lines in a short period of time ;)


All times are GMT -5. The time now is 05:16 AM.