linux 终端屏幕锁

Posted on Posted in bash

linux 终端有个自带的屏幕锁,Ctrl + s 锁定,Ctrl + q 解锁,下面个脚本形式的,可以DIY密码

#! /bin/sh
#
# lockscreen.sh
# Copyright (C) 2017 pi <pi@raspberrypi>

reset;clear	#清除屏幕
info="输入密码!"
cowsay $info
read -p "password: " mypassword
echo "Screen will locked in 3 seconds!"
sleep 3
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 -p "Unlock code: " input
	case $input in
		$mypassword)
			clear
			printf "Hello $USER,Today is $(date +%T)\n"
			stty echo
			break ;;
		*)
			clear
			echo -e "\033[31m 别动我电脑! \033[0m"
	sleep 3
	clear
continue ;;
esac
done
» 转载请注明来源:若我若鱼 » linux 终端屏幕锁

Leave a Reply

Your email address will not be published. Required fields are marked *

five + 17 =