歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> SHELL編程 >> Shell應用編程之開機密碼歡迎welcome

Shell應用編程之開機密碼歡迎welcome

日期:2017/3/1 10:06:34   编辑:SHELL編程

描述:若用戶希望鎖定對終端的訪問,但不想退出並再次登錄,則可以編寫一個Shell腳本程序實現。

當調用該腳本時,知道用戶輸入正確的密碼才能退出。

其中:

  • ctrl + u 刪除整行
  • ctrl + b 刪除前一個字符
  • 粗體顯示字符

shell程源序:

  1. trap " " 2 3 4
  2. stty -echo
  3. #tput bel
  4. stty kill \^u
  5. stty erase \^b
  6. tput bold
  7. #tput blink
  8. tput bel
  9. #tput dim
  10. if [ $# -gt 0 ]
  11. then
  12. MESG="$@"
  13. else
  14. MESG="This system is locked"
  15. fi
  16. tput clear
  17. tput cup 5 10; echo "Enter your passwd>\c"
  18. read pword_1
  19. tput clear
  20. tput cup 10 20;echo "$MESG"
  21. pword_2=
  22. until [ "$pword_1" = "$pword_2" ]
  23. do
  24. tput rev
  25. read pword_2
  26. done
  27. stty echo
  28. tput clear
  29. exit 0

分析:通過trap捕捉信號,設置中斷信號、退出信號均已屏蔽,即ctrl + c,del ,Break鍵均不管用。

Copyright © Linux教程網 All Rights Reserved