#Locking a terminal using a shell script.
#This script locks your terminal until you enter correct password (open2world)
#It also traps signals and interrupts
#You can't terminate the script by Ctrl+c or Ctrl+\ or Ctrl+z and Ctrl+d
#************************************************************************************
clear
trap "" 1 2 3 20
lines=`tput lines`
b=`expr $lines / 2 - 4 `
## center function
center()
{
columns=`tput cols`
until [ -z "$1" ]
do
for ((i=1;i<$(((columns-${#1})/2));i++)) do echo -n " " done echo -e "\033[1m \033[5m \033[42m $1 \033[0m " shift done } ## End of center function while true do clear tput cup $b 0
center " TERMINAL LOCKED "
center "Press any key to unlock"
read key
echo -n "enter password : "
read -s password
while true
do
if [ $password = "open2world" ]
then
clear
break 2
# breaks second outer loop
else
echo -e "\n You are an illegal user "
echo -e "\n Enter any key"
read
break
fi
done
done
Analysis :
The trap command allows you to execute a command when a signal is received by your script. It works like this:
trap arg signals
"signals" is a list of signals to interrupt and "arg" is a command to execute when one of the signals is received. If "arg" is not supplied script doesn't do any thing after receiving signal.
Note: Two signals "SIGKILL" "SIGSTOP" are unable to trap
Ex: trap "echo signal received" 1 2 3 15
(or use SIGHUP SIGINT SIGQUIT SIGTERM instead of 1 2 3 15 )
What is signal:
A signal is a message which can be sent to a running process. Some times called
software interrupts.
Some of signals and its value:
Signal Value Action Comment
-------------------------------------------------------------------------
SIGHUP 1 Term Hangup detected on controlling terminal
or death of controlling process
SIGINT (Ctrl+c) 2 Term Interrupt from keyboard
SIGQUIT (Ctrl+\) 3 Core Quit from keyboard
SIGTERM 15 Term Termination signal
SIGTSTP (Ctrl+z) 20 Stop Stop typed at tty
Note: There are different standards(POSIX,SUSv) to determine signals and its values.
I tested Above signals in Fedora 9, Other systems may support them or not depending on system standard(I think almost all standards supports above signals and values).
More stuff:
I used "tput cols" and "tput lines" commands to collect number of columns and lines.
You can also directly use bash variables $LINES ,$COLUMNS to get columns and lines.But
you should to run your script in current shell only. If you run your script in sub shell
current shell will not export $LINES and $COLUMNS variable values.
Guru Dev
ReplyDeletenot working
ReplyDelete@anonymous: It seems just copy/paste formatting issues
ReplyDelete# Insert breaks after
...
## End of center function
while true
do
clear tput cup $b 0
...
Most of the times we feel that searching for a locksmith online is probably a smart decision. However, we could become a victim of fake or scamming locksmiths who are imitating legitimate ones on the online directories. The case is these fake locksmiths impersonate the local locksmiths and they don't even have any local workshop. Sometimes these so-called locksmiths are not even properly trained and are operated through out-of-state call centers. www.flatratelocknkey-denver.com/
ReplyDeleteA few cautious steps taken by you can help in avoiding a scamming company or an untrained impersonator.
An interesting dialogue is price comment. I feel that it is best to write more on this matter, it may not be a taboo topic however usually individuals are not enough to talk on such topics. To the next. Cheers. Folder Lock Download For PC Desktop - Don't Spend Period Searching, Go through Info On Cell Desktops Inside this article how to open password protected usb stick in windows 8.1
ReplyDeleteHello there. I found your web site by the use of Google at the same time as searching for a comparable subject, your site came up. It seems great. I have bookmarked it in my google bookmarks to come back then.
ReplyDeletePenis Enlargement OilPenis Enlargement OilsPenis Enlargement Oil in IndiaPenis Enlargement Oil in ChennaiBuy Penis Enlargement CreamBuy Penis Enlargement Cream IndiaBuy Penis Enlargement Cream in Chennai
Breast Enlargement Cream Breast Enlargement Cream in India Breast Enlargement Cream in ChennaiTamil Status
Tamil Whatsapp Video Status
WhatsApp Video Status in TamilTamil Status Video
Tamil Status Video Songs DownloadMalayalam WhatsApp Video Status Video SongsTelugu WhatsApp Video Status Video SongsInstant Social Bookmarking List