Group Permission

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: G.D.Thurman
Date:  
Subject: Group Permission
On Thu, 11 Jul 2002, Carl Parrish wrote:

> How do you add a group into a group in the /etc/group file??
>

The following AWK script passed minimal unit testing.

# filename: groupmerge.awk
#
# To merge group b into group a...
# awk -f groupmerge.awk /etc/group a b
#
# caveats: magic #s used; no error handling

BEGIN {
   if (4 != ARGC) {
      printf("Usage:  awk -f groupmerge.awk group_file to_group from_group\n");
      printf("Example:  awk -f groupmerge.awk /etc/group techies cvs");
      exit 1;
   }
   to=ARGV[2];
   from=ARGV[3];
   ARGC=2;
   FS=":";
}
$1 == to {
   d=sprintf("%s:%s:%s:", $1, $2, $3);
   s=$4;
   next;
}
{ printf("%s:%s:%s:%s\n", $1, $2, $3, $4); }
$1 == from {
   g=$4;
}
END {
   printf("%s%s", d, s);
   split(g, groups, ",");
   for (i in groups)
      if (!match(s, groups[i]))     # avoid dups
         printf(",%s", groups[i]);
   printf("\n");
}