Answer the question
In order to leave comments, you need to log in
How to write a password generator in bash?
Decided to learn bash.
There is a need to generate digital passwords according to the following scheme.
At the first stage, the user selects the time range of the password (for example, in the format dd.mm.yyyy hh.mm - hh.mm), not less than an hour and not more than 10 hours. If a password has already been generated for this time period, then the user is informed about this (for example: It is impossible to generate a password for the interval 10/30/2015 22.00-23.00 Since there is a password for the interval 10/30/2015 21.00-10.31.2015 01.00).
At the second stage, the password is generated and saved to a file, the file name corresponds to the time range of the password.
At the third stage, the contents of the file (possibly with a name) are displayed on the screen and (ideally) printed on the printer.
Obstacles appeared already at the first stage.
#!/bin/bash
MATRIX="0123456789"
LENGTH="8"
while [ "${n:=1}" -le "$LENGTH" ]
do
PASS="$PASS${MATRIX:$(($RANDOM% ${#MATRIX})):1}"
let n+=1
done
echo "$PASS"
On the same page where I found this example, I met a negative opinion about this construction and a recommendation to use the following one (completely unreadable for me).
/dev/urandom | grep -o '' | head -n 5 | tr -d '\n'; echo
Is this task even feasible in bash?
PS learned the command to print text files
lpr <filename>
Answer the question
In order to leave comments, you need to log in
base64 /dev/urandom | head -10 | tr -d -c '0-9' | cut -c1-8
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question