Saturday, April 8, 2017
BBM Mod CIBEN 2 9 0 44 APK
BBM Mod CIBEN 2 9 0 44 APK
#************************************************************************************
#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 cant 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 "33[1m 33[5m 33[42m $1 33[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 " You are an illegal user "
echo -e " 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 doesnt 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.
Available link for download