Linux终端怎么锁屏,自制Linux 终端 锁屏防窃助手
很多時候我們不能一直守護在自己的電腦旁邊,而且有些文件并不想讓別人知道。那么這時候來個鎖屏,是再合適不過的了。今天分享一個自制的鎖屏工具,如下。
準備
操作系統 : 我這里是ElementaryOS虛擬機 + XShell 遠程登錄工具
Shell語言 : 我使用的是默認的Bash Shell
其他小工具 :
fortune:系統隨機的從語庫中選出一句英文成語。
cowsay : 在終端界面上顯示出一個奶牛的語句框,配合管道連接上fortune,效果完美!
代碼
#!/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 #清除屏幕
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 #清除屏幕
info="Please input the password you will use later!"
cowsay $info
read mypassword
echo "Screen will locked in 7 seconds!"
sleep 7
clear
#加上這個倒記時的小東東,;)
trapper () { #建立個函數
trap ' ' 2 3 20 #忽略CTRL+C CTRL+\ CTRL+Z信號
}
while : #進入死循環
do
trapper #調用函數
printf "\n\n\n\n\n\n\n\n\t\t\tPlease enter unlock code:" | cowsay
stty -echo #屏蔽輸入的字符
read input
case $input in
$mypassword)
printf "\t\t Hello $USER,Today is $(date +%T)\n"
stty echo
break ;; #輸入正確,挑出循環回到命令行
*)echo "Do not check my files,please! See as follows:"
sleep 3
clear
continue ;; #否則,繼續循環
esac
done
運行演示
程序運行開始:
mark@mark:~/temp/myscripts$ ./lockscreen.sh
______________________________________
/ Please input the password you \
\ will use later! /
--------------------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
123
Screen will locked in 7 seconds!
由于靜態文本沒辦法顯示程序執行過程中的動態效果,所以直接看解鎖界面吧
當我們輸入不正確的密碼的時候,系統會提示輸入錯誤,以及一個幽默的“警告”
___________________________
/ \
\ 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 |
|| ||
當我們密碼輸入正確的時候,如下:
___________________________
/ \
\ Please enter unlock code: /
---------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
Hello mark,Today is 06:35:05
結語
代碼還是很簡單的,僅僅用到了shell腳本語法的幾個小命令。希望我這個腳本能拋磚引玉,打開你的思路,做出更好的鎖屏小腳本!
:-)
總結
以上是生活随笔為你收集整理的Linux终端怎么锁屏,自制Linux 终端 锁屏防窃助手的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux中wps默认安装目录,cent
- 下一篇: 树莓派linux系统识别u盘启动,树莓派