-
-
Save napcs/5770708 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
PREFIX=$1 | |
COUNT=$2 | |
PASS=$3 | |
# validation | |
if [ $# -ne 3 ]; then | |
echo "Usage: $0 <prefix> <count> <password>" | |
exit | |
fi | |
# hash password | |
PASS=$(openssl passwd -1 $PASS) | |
# create | |
for i in $(seq 1 $COUNT) | |
do | |
# setup student account, zero padded to two characters | |
# with a password | |
S=$(printf "${PREFIX}%02d" $i) | |
D=/home/$S | |
useradd -m -p $PASS -s /bin/bash $S | |
if [ $? -eq 0 ]; then | |
# remove group/other read/execute access | |
chmod 700 $D | |
# fix .bashrc for default PuTTY character set | |
echo -e "\nexport LANG=en_US.iso88591" >> $D/.bashrc | |
# fix wall/talk to prevent annoying students | |
echo -e "\nmesg n" >> $D/.bashrc | |
echo "Created $S" | |
else | |
echo "Could not create $S" | |
fi | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
PREFIX=$1 | |
COUNT=$2 | |
# validation | |
if [ $# -ne 2 ]; then | |
echo "Usage: $0 <prefix> <count>" | |
exit | |
fi | |
# remove | |
for i in $(seq 1 $COUNT) | |
do | |
# setup student account, zero padded to two characters | |
# with a password | |
export S=$(printf "${PREFIX}%02d" $i) | |
userdel -r $S | |
if [ $? -eq 0 ]; then | |
echo "Removed $S" | |
else | |
echo "Could not remove $S" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment