Here is my first “real” script. It does what it was designed to do, but not as nicely as I would have liked. So needless to say there will be some updating. As for the script itself it is supposed to prompt the user for a password before opening firefox. If a password doesn’t currently exist it will ask them to make a new one, that will be saved into a “hidden” file. Really it’s pretty easy to get around but it should be enough to keep your computer illiterate friends away/busy at least.
Here is the script:
#!/bin/bash cd <path> #location of password file there=false ls -a | egrep '^\.' > mytemp #chek if file with password exists while read f do if [ "$f" = ".myPw" ]; then there=true; fi done < mytemp rm mytemp #if not make it if [ "$there" = "false" ]; then echo "Enter a password:" read newPass echo $newPass > .myPw chmod 777 .myPw #make possible to read and write to file (needed for later on) fi input=: correct=false j=: #get actuall password while read j do PW=$j done < .myPw #read until correct pw is given while [ "$correct" = "false" ] do echo "Enter password or ^C (Ctrl + C) to quit:" read input if [ "$input" = "$PW" ] then correct=true else echo "Incorrect password" fi done firefox& while : do ii=2 done
Sorry it’s not in the best font but at least the formatting is there. Anyway the part I don’t like is the infinite loop at the end. However, I haven’t found a way to keep firefox open if it’s not there. With out it, once the correct password is entered the script will end but firefox won’t start.
Well in my next post I’ll try to explain what each line does. Should be a good exercise in talking about terminal commands.