Seconds From Now Till Then

Discussion in 'NZ Computing' started by Lawrence D'Oliveiro, Apr 1, 2010.

  1. The following Bash function returns the number of seconds from now until the
    specified time:

    till() { echo $(($(date -d "$1" +%s) - $(date +%s))); }

    For example, how long is it until 6 o’clock:

    ldo@theon:~> till 06:00
    20932

    What’s the value of this? You can delay until a particular time before
    performing an action, e.g.

    sleep $(till 07:30); echo 'Wakey! Wakey!'
     
    Lawrence D'Oliveiro, Apr 1, 2010
    #1
    1. Advertising

  2. Lawrence D'Oliveiro

    Enkidu Guest

    Lawrence D'Oliveiro wrote:
    > The following Bash function returns the number of seconds from now until the
    > specified time:
    >
    > till() { echo $(($(date -d "$1" +%s) - $(date +%s))); }
    >
    > For example, how long is it until 6 o’clock:
    >
    > ldo@theon:~> till 06:00
    > 20932
    >
    > What’s the value of this? You can delay until a particular time before
    > performing an action, e.g.
    >
    > sleep $(till 07:30); echo 'Wakey! Wakey!'
    >

    Why not just use 'at'? Otherwise you have your bash script hanging
    around until 7:30, doing nothing.

    Cheers,

    Cliff

    --

    The ends justifies the means - Niccolò di Bernardo dei Machiavelli.

    The end excuses any evil - Sophocles
     
    Enkidu, Apr 1, 2010
    #2
    1. Advertising

  3. Lawrence D'Oliveiro

    AD. Guest

    On Apr 2, 12:15 am, Lawrence D'Oliveiro <l...@geek-
    central.gen.new_zealand> wrote:
    > The following Bash function returns the number of seconds from now until the
    > specified time:
    >
    >     till() { echo $(($(date -d "$1" +%s) - $(date +%s))); }
    >
    > For example, how long is it until 6 o’clock:
    >
    >     ldo@theon:~> till 06:00
    >     20932
    >
    > What’s the value of this? You can delay until a particular time before
    > performing an action, e.g.
    >
    >     sleep $(till 07:30); echo 'Wakey! Wakey!'


    better:

    ! sleep $(till hammersmith)

    or if you prefer a different genre:

    ! sleep $(till brooklyn)

    --
    Cheers
    Anton
     
    AD., Apr 1, 2010
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. don ward

    cd plays 10 seconds then advances

    don ward, Oct 18, 2005, in forum: Computer Support
    Replies:
    3
    Views:
    428
    =?ISO-8859-1?Q?R=F4g=EAr?=
    Oct 18, 2005
  2. unbroken
    Replies:
    8
    Views:
    849
    Luke Hague
    Jan 19, 2004
  3. Robert J. Stevens

    Computer Wont Start Fan Runs 3 seconds then stops

    Robert J. Stevens, Jul 7, 2006, in forum: Computer Support
    Replies:
    10
    Views:
    1,341
    Frosty
    Jul 9, 2006
  4. jjoensuu
    Replies:
    2
    Views:
    869
  5. Cody
    Replies:
    2
    Views:
    3,593
    John Wunderlich
    Jun 28, 2009
Loading...

Share This Page