LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 08-06-2004, 02:20 PM   #1
TechNett
LQ Newbie
 
Registered: Aug 2004
Location: Washingtonville, NY USA
Distribution: RH9
Posts: 5

Rep: Reputation: 0
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
 
Old 08-06-2004, 03:27 PM   #2
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 242Reputation: 242Reputation: 242
you may also consider

id -g <username>
 
Old 08-06-2004, 03:39 PM   #3
TechNett
LQ Newbie
 
Registered: Aug 2004
Location: Washingtonville, NY USA
Distribution: RH9
Posts: 5

Original Poster
Rep: Reputation: 0
In what context would I use 'id -g <username>?
How would that be written into a script?
Thanks!
Nett
 
Old 08-06-2004, 03:44 PM   #4
TechNett
LQ Newbie
 
Registered: Aug 2004
Location: Washingtonville, NY USA
Distribution: RH9
Posts: 5

Original Poster
Rep: Reputation: 0
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
 
Old 08-06-2004, 03:51 PM   #5
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 242Reputation: 242Reputation: 242
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

Last edited by Cedrik; 08-06-2004 at 03:57 PM.
 
Old 08-09-2004, 03:24 PM   #6
TechNett
LQ Newbie
 
Registered: Aug 2004
Location: Washingtonville, NY USA
Distribution: RH9
Posts: 5

Original Poster
Rep: Reputation: 0
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
 
Old 08-09-2004, 03:45 PM   #7
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 242Reputation: 242Reputation: 242
I am sure you will find a way to reduce it to say 7/8 lines in a short period of time
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I change a user's primary group? Akhran Linux - Newbie 4 03-19-2010 09:54 PM
Changing a user's group at login depending on the time of day Steve2001 Linux - General 10 10-11-2004 04:29 AM
Changing user's group? orange400 Linux - General 2 06-18-2004 05:30 AM
Changing a user's default group dogn00dles Linux - Security 4 07-09-2003 04:59 PM
RED HAT 7.1 ... how to set up quota for group matthew_wu Linux - Newbie 1 06-15-2001 05:56 PM


All times are GMT -5. The time now is 02:50 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration