Skip to content

Instantly share code, notes, and snippets.

@dw72
Last active December 14, 2017 10:42
Show Gist options
  • Save dw72/1991dfec1abacc43184d32c52c17c9f2 to your computer and use it in GitHub Desktop.
Save dw72/1991dfec1abacc43184d32c52c17c9f2 to your computer and use it in GitHub Desktop.
Add students accounts from csv file on Linux
#!/bin/bash
OLDIFS=$IFS
IFS=","
while read class profil lastname firstname pesel
do
first=$(echo $firstname | iconv -f UTF-8 -t ASCII//translit | cut -c 1-2)
last=$(echo $lastname | iconv -f UTF-8 -t ASCII//translit)
login=$(echo "$class.$last.$first" | tr '[:upper:]' '[:lower:]')
passwd=$(openssl passwd -1 ${pesel})
useradd -c "${firstname} ${lastname}" -d /home/"${login}" -G users -s /bin/bash -p ${passwd} ${login}
done < students.csv
IFS=$OLDIFS
#!/bin/bash
OLDIFS=$IFS
IFS=","
while read class profil lastname firstname pesel
do
first=$(echo $firstname | iconv -f UTF-8 -t ASCII//translit | cut -c 1-2)
last=$(echo $lastname | iconv -f UTF-8 -t ASCII//translit)
login=$(echo "$class.$last.$first" | tr '[:upper:]' '[:lower:]')
passwd=$(openssl passwd -1 ${pesel})
userdel -r ${login}
done < students.csv
IFS=$OLDIFS
#!/bin/bash
OLDIFS=$IFS
IFS=","
while read class profil lastname firstname pesel
do
first=$(echo $firstname | iconv -f UTF-8 -t ASCII//translit | cut -c 1-2)
last=$(echo $lastname | iconv -f UTF-8 -t ASCII//translit)
login=$(echo "$class.$last.$first" | tr '[:upper:]' '[:lower:]' | tr '.' '_')
echo "CREATE USER '$login'@'%' IDENTIFIED BY '$pesel';" >> users.sql
echo "REVOKE ALL PRIVILEGES ON *.* FROM '$login'@'%';" >> users.sql
echo "REVOKE GRANT OPTION ON *.* FROM '$login'@'%';" >> users.sql
echo "GRANT ALL PRIVILEGES ON \`$login\_%\`.* TO '$login'@'%' REQUIRE NONE WITH MAX_QUERIES_PER_HOUR 5000 MAX_CONNECTIONS_PER_HOUR 2000 MAX_UPDATES_PER_HOUR 2000 MAX_USER_CONNECTIONS 3;" >> users.sql
done < mysql.csv
IFS=$OLDIFS
2f Technik informatyk Dudziak Jan 93122609051
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment