Install makepasswd
apt-get install makepasswd
makepasswd usage
makepasswd –chars=N, where N is the length you want the password to be generated.
The default –minchars is 8 and –maxchars is 10.
Objective make a short script to generate password using makepasswd program.
#!/bin/bash
#randomly generate 8 character password with makepasswd.
n=$1
if [ “$n” != “0” ]; then
/usr/bin/makepasswd –chars=$n
else echo “Zero not allowed”
fi
Usage:
root@bt:/home/passwd# ./mp.sh 10
mzHGSQDiYB
Note: When comparing numerical values, quotation must be used to enclose the variable and the number. Number is treated as string. For bash script, if loop, while loop and other loop uses square brackets […..] and not (…..).
Bash user input argument:
$1 = first argument.
$2 = second argument.
$3 = third argument.
and so on and so forth.
Arguments example:
#!/bin/bash
echo “first argument : $1”
echo “second argument : $2”
echo “third argument : $3”
echo “fourth argument : $4”
Usage:
./ex1.sh 100 200 300 400
first argument : 100
second argument : 200
third argument : 300
fourth argument : 400
Reference: http://www.bashguru.com/2009/11/how-to-pass-arguments-to-shell-script.html
Reference: http://www.johnstowers.co.nz/blog/index.php/reference/bash-cheat-sheet/
One thought on “Simple bash script”