Shell-trap-lock terminal screen, shell-trap-lock Terminal
Shell-trap-lock terminal screen
#! /Bin/bash # lock the terminal # Shield the termination signal, press ctrl + c to execute the lock_nice function trap "lock_nice" 2 3 15 # The Anti-quotation mark TTY = 'tty 'lock _ nice () on the tab key () {echo-e "\ r Nice. lock nice. the terminal stays locked! \ R "} SAVEDSTTY = 'stty-G' # do not display the input character stty-echoecho-n-e" Enter you passwd to lock $ TTY: "read PASSWDecho-e" \ r "while: do # read form tty only !! Echo-e-n "input passwd for unlock:" read RESPONSE <$ TTY echo-e "\ r" if ["$ RESPONSE" = "$ PASSWD"]; then echo "unlocking... "breakfi # wrong passwd. return lock_nice echo-e "wrong passwd and terminal is locked! \ R "done # display stty $ SAVEDSTTY in terminal readable format
You can also set a password.
#! /Bin/bash # lock the terminaltrap "lock_nice" 2 3 15TTY = 'tty 'lock _ nice () {echo-e "\ r Nice. lock nice. the terminal stays locked! \ R "} SAVEDSTTY = 'stty-G' PASSWD = qwewhile: do # read form tty only !! Echo-e-n "input passwd for unlock:" read RESPONSE <$ TTY echo-e "\ r" if ["$ RESPONSE" = "$ PASSWD"]; then echo "unlocking... "breakfi # wrong passwd. return lock_nice echo-e "wrong passwd and terminal is locked! \ R "done # display stty $ SAVEDSTTY in terminal readable format