




|
Tech Tips5
How to use bash to compile a password producer?
Author: Ben|Date: 2007/06/07|Back to Tech Tips
很多MIS人員常常為了設定公司員工的密碼,而想不出一個簡單的方法;Ben老師在
課堂上給學員的作業便是,請各位學員使用bash寫出一個密碼產生器。
#!/bin/bash declare -i count=0 chars='1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOQPRSTUVWXYZ._!@#$%^&*()' declare -i chars_length=`expr length $chars` while [ $count -le 7 ] do declare -i pos=`expr $RANDOM % $chars_length`+1 #Double quotation mark is necessary otherwise the following current directory files will be presented if echo is ‘*’: echo -n "`expr substr $chars $pos 1`" count=$count+1 done echo |