Results 1 to 4 of 4
Hi everyone, i got a problem in this shell scripts where during my execute time, in my third tries, if i enter a correct password then the program still activated ...
- 10-13-2009 #1Just Joined!
- Join Date
- Oct 2009
- Posts
- 5
Problem Solving
Hi everyone, i got a problem in this shell scripts where during my execute time, in my third tries, if i enter a correct password then the program still activated my time, anyone can help me to correct my problem ?
#!/bin/bash
time=60
tries=3
start=$(date +%s)
left=$time
while true;do
read -t $left -p "Code: " code
((tries--))
left=$(($time-$(date +%s)+start))
if (( $left<=0 || $tries==0 ));then
echo "Time Activated"
break
fi
if [[ "$code" == "abcde" ]];then
echo "Correct!! Time Deactivated"
break
else
echo "Wrong! Please Try again. There are $left seconds and $tries tries left."
fi
done
exit
- 10-13-2009 #2Linux User
- Join Date
- Jan 2007
- Location
- cleveland
- Posts
- 452
nice little script; a slight reordering
seems to make it work OK--
#!/bin/bash
time=60
tries=3
start=$(date +%s)
left=$time
while true
do
left=$(($time-$(date +%s)+start))
read -t $left -p "Code: " code
((tries--))
if [[ "$code" == "abcde" ]];then
echo "Correct!! Time Deactivated"
break
else
if (( $left<=0 || $tries==0 ));then
echo "Time Activated"
break
fi
echo "Wrong! Please Try again. There are $left seconds and $tries tries left."
fi
done
exitthe sun is new every day (heraclitus)
- 10-13-2009 #3Just Joined!
- Join Date
- Oct 2009
- Posts
- 5
dear tpl : i have try it.. and it works.. but there is one error there happen where during second tries, if we just wait during second tries and wait until time activated it will show there
Code: wrong! please try again. There are 50++ seconds and 1 tries left.
Time Activated
isn't this is not relevant since we are failed to enter the code during second time, and there should be just echo out "Time Activated".. u get what i mean?
hope you can help me to share your idea with me..
- 10-16-2009 #4forum.guy
- Join Date
- May 2004
- Location
- arch linux
- Posts
- 18,096
Hi, Linuxpeguinkit... it's against the forum rules to post duplicate threads. so please stop creating them and continue any discussion in this thread. Your duplicate threads/posts have been deleted. Thank you.
oz
→ new members/users: read this first | new member faq
→ no private messages requesting computer support - post them on the forums!
→ please use the "report post" button to alert our forum admins to problematic posts rather than responding to them yourself.


Reply With Quote
