Shell应用编程之开机密码欢迎welcome
Shell应用编程之开机密码欢迎welcome
描述:若用户希望锁定对终端的访问,但不想退出并再次登录,则可以编写一个Shell脚本程序实现。
当调用该脚本时,知道用户输入正确的密码才能退出。
其中:
- ctrl + u 删除整行
- ctrl + b 删除前一个字符
- 粗体显示字符
shell程源序:
- trap " " 2 3 4
- stty -echo
- #tput bel
- stty kill \^u
- stty erase \^b
- tput bold
- #tput blink
- tput bel
- #tput dim
- if [ $# -gt 0 ]
- then
- MESG="$@"
- else
- MESG="This system is locked"
- fi
- tput clear
- tput cup 5 10; echo "Enter your passwd>\c"
- read pword_1
- tput clear
- tput cup 10 20;echo "$MESG"
- pword_2=
- until [ "$pword_1" = "$pword_2" ]
- do
- tput rev
- read pword_2
- done
- stty echo
- tput clear
- exit 0
分析:通过trap捕捉信号,设置中断信号、退出信号均已屏蔽,即ctrl + c,del ,Break键均不管用。
评论暂时关闭