Code:#!/bin/bash function term { echo you are late! exit 1 } TIMEOUT=10 PID=$$ trap "term" TERM (sleep $TIMEOUT && kill -SIGTERM $PID) & TIMER=$! read -p "Enter a string in $TIMEOUT seconds: " STRING kill -SIGTERM $TIMER echo $STRING
This is a discussion on Unsolve counter - Shell Scripting ; Hi there, I have a unsolved problem here...my scripting do not go as I want, actually I want it to be solving the password in 10 seconds, but my scripting is run the timer and then only run the password ...
Hi there, I have a unsolved problem here...my scripting do not go as I want, actually I want it to be solving the password in 10 seconds, but my scripting is run the timer and then only run the password solving.... anyone got any idea how to combine it??
#!/bin/bash
function timer
{
local OLD_IFS="${IFS}"
IFS=":"
local ARR=( $1 )
local SECONDS=$(( (ARR[0] * 60 * 60) + (ARR[1] * 60) + ARR[2] ))
local START=$(date +%s)
local END=$((START + SECONDS))
local CUR=$START
while [[ $CUR -lt $END ]]
do
CUR=$(date +%s)
LEFT=$((END-CUR))
printf "\r%02d:%02d:%02d" \
$((LEFT/3600)) $(( (LEFT/60)%60)) $((LEFT%60))
sleep 1
done
IFS="${OLD_IFS}"
echo " "
}
timer "00:00:10"
time=30
tries=3
start=$(date +%s)
left=$time
while true
do
left=$(($time-$(date +%s)+start))
read -t $left -p "Code: " code
((tries--))
if [[ "$code" == "1234567890" ]]; then
echo "CORRECT!!! Game Deactivated"
break
else
if (( $left<=0 || $tries==0 ));then
echo "Game Activated!!!"
break
fi
echo "WRONG!!! Please Try Again... There are $left seconds and $tries left."
fi
done
exit
Code:#!/bin/bash function term { echo you are late! exit 1 } TIMEOUT=10 PID=$$ trap "term" TERM (sleep $TIMEOUT && kill -SIGTERM $PID) & TIMER=$! read -p "Enter a string in $TIMEOUT seconds: " STRING kill -SIGTERM $TIMER echo $STRING