Make your own Linux terminal lock screen tool

  • 2020-05-10 23:23:02
  • OfStack

A lot of times we can't keep a straight line to our computers, and some files we don't want anyone to know about. A lock screen is perfect. Today we share a homemade lock screen tool as follows.

To prepare
  & # 8226; Operating system: this is ElementaryOS virtual machine + XShell remote login tool
  & # 8226; Shell language: I use the default Bash Shell
  & # 8226; Other gadgets:  
              ◦ fortune: a systematic and random selection of an English idiom from a corpus.
                ◦ cowsay: a statement box of a cow is displayed on the terminal interface, and fortune is connected with the pipe, perfect effect!

  code


#!/bin/bash
#scriptname:locktty
#writed by :Marksinoberg
#description : just for protecting our message when we leave away. And we can set the password every time.

reset;clear # Clear the screen 
info="Please input the password you will use later!"
cowsay $info
read mypassword
echo "Screen will locked in 7 seconds!"
sleep 7
clear
#!/bin/bash
#scriptname:locktty
#writed by :javalee
#script start...
reset;clear # Clear the screen 
info="Please input the password you will use later!"
cowsay $info
read mypassword
echo "Screen will locked in 7 seconds!"
sleep 7
clear
# Plus this little clock thing ,;)

trapper () { # Set up a function 
trap ' ' 2 3 20 # ignore CTRL+C CTRL+\ CTRL+Z signal 
}
while : # Go into a dead cycle 
do
trapper # Call a function 
printf "\n\n\n\n\n\n\n\n\t\t\tPlease enter unlock code:" | cowsay
stty -echo  # Mask the input character 
read input
case $input in
$mypassword)
printf "\t\t Hello $USER,Today is $(date +%T)\n"
stty echo  
break ;;  # Input the correct , Loop back to the command line 
*)echo "Do not check my files,please! See as follows:"
sleep 3
clear
continue ;;  # Otherwise, , Continue to cycle 
esac
done

Run the demo

Program start:

mark@mark:~/temp/myscripts$ ./lockscreen.sh


  ______________________________________
/ Please input the password you               \
\         will use later!                                   /
  --------------------------------------
              \     ^__^
                \   (oo)\_______
                      (__)\             )\/\
                              ||----w |
                              ||         ||
123
Screen will locked in 7 seconds!

Since static text can't display dynamic effects during program execution, look directly at the unlock screen
When we enter an incorrect password, the system will prompt us with an error and a humorous "warning".

  ___________________________
/                                                     \
\ Please enter unlock code: /
  ---------------------------
              \     ^__^
                \   (oo)\_______
                      (__)\             )\/\
                              ||----w |
                              ||         ||
Do not check my files,please! See as follows:
  _________________________________________
/ Q: Why is it that the more accuracy you \
| demand from an interpolation                       |
|                                                                                 |
| function, the more expensive it becomes |
| to compute? A: That's the Law of Spline |
\ Demand.                                                                 /
  -----------------------------------------
              \     ^__^
                \   (oo)\_______
                      (__)\             )\/\
                              ||----w |
                              ||         ||

When we enter the correct password, it is as follows:

  ___________________________
/                                                     \
\ Please enter unlock code: /
  ---------------------------
              \     ^__^
                \   (oo)\_______
                      (__)\             )\/\
                              ||----w |
                              ||         ||
                Hello mark,Today is 06:35:05

conclusion

The code is simple, using only a few small commands from the shell script syntax. I hope this script can be a brick to attract jade, open your mind, to make a better lock screen small script!


Related articles: