Last active
October 5, 2018 16:44
-
-
Save naotaco/21e9335538cecf03ad42e25c6a0b497e to your computer and use it in GitHub Desktop.
適当にnginx用のid/password生成する君
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 | |
# Usage: ./gen_users.sh [num] [dest_dir(option)] | |
NUM=$1 # number of accounts | |
DIR_NAME=$2 | |
PW_FILE=./.htpasswd # for nginx setting | |
CSV_FILE=./id_list.csv # for print | |
if [ -z $DIR_NAME ]; then | |
DIR_NAME=$(date +%F_%H_%M_%S) | |
else | |
PW_FILE=./.htpasswd_$DIR_NAME | |
CSV_FILE=./id_list_${DIR_NAME}.csv | |
fi | |
if [ -e $DIR_NAME ]; then | |
echo "Already exists. Remove it first." | |
exit 1 | |
fi | |
mkdir $DIR_NAME | |
cd $DIR_NAME | |
touch $PW_FILE | |
echo "id,password" > $CSV_FILE | |
echo "Generating accounts in $DIR_NAME ..." | |
for ((i=0; i<NUM; i++)); | |
do | |
line=$(pwgen -C -A 8 2) # generate two random strings as ID/PW | |
echo $line | sed -e 's/\ /,/g' >> $CSV_FILE | |
htpasswd -b -m $PW_FILE $line > /dev/null 2>&1 | |
printf . | |
done | |
echo "$NUM accounts created." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
usage: