奇科電腦 回奇科電腦首頁奇科電腦LPI課程資訊奇科電腦Embedded課程資訊奇科電腦Cisco課程資訊奇科電腦Programming課程資訊奇科電腦Smartphone App課程資訊
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


Best Browse: 1024x768 Copyright 2010 GeeGo Systems, Ltd.
service@geego.com.tw|DL: 0800-296-296|3F., No.60, Zhulun St., Zhongshan Dist., Taipei City 104, Taiwan (R.O.C.)|02-2711-6373