I have this exercise: Create a "groups" BASH shell script, which takes as an argument a groups_file.txt
file structured as follows:
adm:x:4:syslog,adm1
admins:x:1006:adm2,adm12,manuel
ssl-cert:x:122:postgres
alan2:x:1009:aceto,salvemini
conda:x:1011:giovannelli,galise,aceto,caputo,haymele,salvemini,scala,adm2,adm12
adm1Group:x:1022:adm2,adm1,adm3
docker:x:998:manuel
that:
prints the maximum number of fields on a line in a given file
creates a subdirectory for each group in the file, giving read and write access to users of the groups "adm" and "admins"
creates a file for each subdirectory containing the users belonging to that group line by line
I did the first two points but I don't know how to do the last one. I tried to get the groups equal to $1 with awk and then I redirected them to the "$group/user" file but it doesn't work
#!/bin/bash
echo "Stampo il numero massimo di campi di una linea in un dato file: "
cat groups_file.txt | awk -F "[\t,:]" 'NF>6 {print $0}'
g=$(cat groups_file.txt | awk -F : '{print $1}')
for group in $g
do
mkdir "$group"
chmod +rwx "$group"
touch "$group"/users
chmod +rw "$group"/users
done