Skip to content

Instantly share code, notes, and snippets.

@CroneKorkN
Last active September 5, 2017 08:49
Show Gist options
  • Save CroneKorkN/08b1b765a0c3101faac53c3576690b1c to your computer and use it in GitHub Desktop.
Save CroneKorkN/08b1b765a0c3101faac53c3576690b1c to your computer and use it in GitHub Desktop.
#!/bin/bash
colleagues="accounting roy
accounting rainer
sales volker
sales vera
personell paula
personell peter
director gertrud
workscouncil gertrud
workscouncil roy"
IFS=$'\n' # Split by newline
#
# 1a)
#
for line in $colleagues; do
group=$(echo $line | awk '{print $1;}')
groups="$groups $group" # collect groups
name=$(echo $line | awk '{print $2;}')
addgroup $group
echo "adduser $name --ingroup $group --disabled-login"
adduser $name --ingroup $group --gecos "" --disabled-login
echo "$name:$name" | chpasswd
done
#
# 1b,d)
#
groups=$(echo $groups | tr ' ' '\n' | uniq)
echo $groups
for group in $groups; do
mkdir -p /transfer/$group
chgrp $group /transfer/$group
chmod 770 /transfer/$group
shareline="/transfer/$group $group(ro)"
if ! grep "$shareline" /etc/exports; then
echo $shareline >> /etc/exports
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment