Sponsored Content
Full Discussion: change
Homework and Emergencies Homework & Coursework Questions change Post 302357331 by ripat on Tuesday 29th of September 2009 11:09:38 AM
Old 09-29-2009
There are two things, the number of tries and the running clock. The -t option of the read internal command takes care of the timout while the shell wait for the user input.

But you have to implement a general timer that will start as soon as the script starts. For that, use the date function converted in number of seconds since EPOCH. That's the idea. Try this:

Code:
#!/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 "BOOOOM"
        break
    fi
    if [[ "$code" == "boom" ]];then
        echo "Correct. Bomb defused"
        break
    else
        echo "Wrong. Try again. There are $left seconds and $tries tries left."
    fi
done
exit

And.. please use the CODE tags for clarity.

Last edited by ripat; 09-29-2009 at 01:14 PM.. Reason: some fixing
 

8 More Discussions You Might Find Interesting

1. Cybersecurity

How to change ip ?

hi , Is there anyway to change ip on sco5.04 i tried using netconfig on the prompt but gives me error . how do u manually change ip cant use acoadmin and netconfig .... thx art (2 Replies)
Discussion started by: art_malabanan
2 Replies

2. Post Here to Contact Site Administrators and Moderators

Want to change my Name

Hello, Pls change my login name to Awadhesh instead of awadhesh if possible. it will be more better if it become Awadhesh Pandey. Thanks a lot. Awadhesh (2 Replies)
Discussion started by: Awadhesh
2 Replies

3. Solaris

Change IP

hello How can i change the ip address on my solaris sun 9 server ? thank you (7 Replies)
Discussion started by: pascalbout
7 Replies

4. Shell Programming and Scripting

change wc -l

Hi, I would like realize a script that it can change " wc -l" with "wc -l | sed 's/ //g'", but my problem is that i can have a pipe ,a variable ( many variable different) or a file after wc -l ?how i could test this several case ? wc -l | cut -d' ' -f1` if wc -l ${F} | awk... (1 Reply)
Discussion started by: francis_tom
1 Replies

5. Shell Programming and Scripting

ksh; Change file permissions, update file, change permissions back?

Hi, I am creating a ksh script to search for a string of text inside files within a directory tree. Some of these file are going to be read/execute only. I know to use chmod to change the permissions of the file, but I want to preserve the original permissions after writing to the file. How can I... (3 Replies)
Discussion started by: right_coaster
3 Replies

6. Shell Programming and Scripting

Change the content of files but not change the date

I have 100 files in a directory , all the files have a word "error" and they are created in different date . Now I would like to change the word from "error" to "warning" , and keep the date of the files ( that means do not change the file creation date after change the word ) , can advise what can... (0 Replies)
Discussion started by: ust3
0 Replies

7. Shell Programming and Scripting

Change the content of files but not change the date

I have 100 files in a directory , all the files have a word "error" and they are created in different date . Now I would like to change the word from "error" to "warning" , and keep the date of the files ( that means do not change the file creation date after change the word ) , can advise what can... (7 Replies)
Discussion started by: ust3
7 Replies

8. SCO

How to change raid controller driver ? (hardware change)

Hello I'm trying to virtualize an instance of Sco Unix 5.0.5 in VirtualBox (called VM-A) , but sco I have problems set to launch with the new raid controller . The physical machine has a raid controller adaptec (alad driver) but VirtualBox uses buslogic (blc driver) What ... (3 Replies)
Discussion started by: flako
3 Replies
FAKETIME(1)							     W.Hommel							       FAKETIME(1)

NAME
faketime - manipulate the system time for a given command SYNOPSIS
faketime [options] timestamp program [arguments...] DESCRIPTION
The given command will be tricked into believing that the current system time is the one specified in the timestamp. The wall clock will continue to run from this date and time unless specified otherwise (see advanced options). Actually, faketime is a simple wrapper for lib- faketime, which uses the LD_PRELOAD mechanism to load a small library which intercepts system calls to functions such as time(2) and fstat(2). This wrapper exposes only a subset of libfaketime's functionality; please refer to the README file that came with faketime for more details and advanced options. OPTIONS
--help show usage information and quit. --version show version information and quit. -m use the multi-threading variant of libfaketime. -f use the advanced timestamp specification format. EXAMPLES
faketime 'last Friday 5 pm' /bin/date faketime '2008-12-24 08:15:42' /bin/date faketime -f '+2,5y x10,0' /bin/bash -c 'date; while true; do echo $SECONDS ; sleep 1 ; done' faketime -f '+2,5y x0,50' /bin/bash -c 'date; while true; do echo $SECONDS ; sleep 1 ; done' (Please note that it depends on your locale settings whether . or , has to be used for fractional offsets) ADVANCED TIMESTAMP FORMAT
The simple timestamp format used by default applies the /bin/date -d command to parse user-friendly specifications such as 'last friday'. When using the faketime option -f, the timestamp specified on the command line is directly passed to libfaketime, which enables a couple of additional features such as speeding the clock up or slowing it down for the target program. It is strongly recommended that you have a look at the README file that came with faketime for the details. Summary: Freeze clock at absolute timestamp: "YYYY-MM-DD hh:mm:ss" If you want to specify an absolute point in time, exactly this format must be used. Please note that freezing the clock is usually not what you want and may break the application. Only use if you know what you're doing! Relative time offset: "[+/-]123[m/h/d/y], e.g. "+60m", "+2y" This is the most often used format and specifies the faked time relatively to the current real time. The first character of the for- mat string must be a + or a -. The numeric value by default represents seconds, but the modifiers m, h, d, and y can be used to specify minutes, hours, days, or years, respectively. For example, "-2y" means "two years ago". Fractional time offsets can be used, e.g. "+2,5y", which means "two and a half years in the future". Please note that the fraction delimiter depends on your locale set- tings, so if "+2,5y" does not work, you might want to try "+2.5y". Start-at timestamps: "@YYYY-MM-DD hh:mm:ss" The wall clock will start counting at the given timestamp for the program. This can be used for specifying absolute timestamps with- out freezing the clock. ADVANCED USAGE
When using relative time offsets or start-at timestamps (see ADVANCED TIMESTAMP FORMAT above and option -f), the clock speed can be adjusted, i.e. time may run faster or slower for the executed program. For example, "+5y x10" will set the faked time 5 years into the future and make the time pass 10 times as fast (one real second equals 10 seconds measured by the program). Similarly, the flow of time can be slowed, e.g. using "-7d x0,2", which will set the faked time 7 days in the past and set the clock speed to 20 percent, i.e. it takes five real world seconds for one second measured by the program. Again, depending on your locale, either "x2.0" or "x2,0" may be required regarding the delimiter. Faking times for multiple programs or even system-wide can be simplified by using ~/.faketimerc files and /etc/faketimerc. Please refer to the README that came with faketime for warnings and details. AUTHOR
Maintained by Wolfgang Hommel <wolf@code-wizards.com>. Please see the README and Changelog files for contributers. BUGS
Due to limitations of the LD_PRELOAD mechanism, faketime will not work with suidroot and statically linked programs. While timestamps and time offsets will work for child processes, speeding the clock up or slowing it down might not work for child processes spawned by the exe- cuted program as expected; a new instance of libfaketime is used for each child process, which means that the libfaketime start time, which is used in speed adjustments, will also be re-initialized. REPORTING BUGS
Please send an e-mail to Wolfgang Hommel <wolf@code-wizards.com> COPYRIGHT
Copyright (C) 2003-2008 by Wolfgang Hommel. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. You may redistribute copies of faketime under the terms of the GNU General Public License. For more information about these matters, see the file named COPYING. SEE ALSO
ld.so(1), time(2), fstat(2) faketime 0.8 August 2008 FAKETIME(1)
All times are GMT -4. The time now is 04:02 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy