I’m writing some scripts to manage users with specifics quotas on a server.
So, to apply a quota like 10GB to all the users in the group quota10, I’m using “setquota -p”, but I have several groups.
So I made a script to manage all users from all groups.
#!/bin/zsh
groups=(1002 1007)
for gid in $groups
echo $gid
echo $(awk -F: '$4 == gid {print $1}' gid=$gid /etc/passwd)
But when I execute it, there is only the last group which give me users in this group.
/etc/passwd
kimino:x:1010:1002::/home/kimino:/bin/bash
kiminoo:x:1011:1007::/home/kiminoo:/bin/bash
/etc/group
quota10:x:1002:
quota20:x:1007:
Output of my script
# ./apply_quota_on_users.zsh
1002
1007
kiminoo
Do you have any idea about what’s wrong ?
You have to wrap your functions in a block: