闲来无事,帮朋友写一个批量生成用户名及随机密码的小工具
- #!/bin/bash
- if [ -z "$1" ]
- then
- echo "Usage: ./genpasswd [-u user id] [-n user numbers] [-f password file]"
- exit 1
- fi
- # get options
- while getopts "u:n:f:" arg
- do
- case $arg in
- u)
- USER=$OPTARG
- ;;
- n)
- NUMS=$OPTARG
- ;;
- f)
- FILE=$OPTARG
- ;;
- ?)
- echo "Usage: ./genpasswd [-u userid] [-n numbers] [-f file]"
- exit 1
- ;;
- esac
- done
- # debug
- #echo $USER
- #echo $NUMS
- #echo $FILE
- # generate password
- while [ $NUMS -gt 0 ]
- do
- USER=`expr $USER + 1`
- NUMS=`expr $NUMS - 1`
- PASSWD=`mkpasswd.pl -C 0 -s 0`
- echo "$USER:$PASSWD" >> $FILE
- done
原创文章,作者:carmelaweatherly,如若转载,请注明出处:https://blog.ytso.com/185258.html