LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   For Fun: Have a Unix time party (https://www.linuxquestions.org/questions/linux-general-1/for-fun-have-a-unix-time-party-700865/)

mmatt 01-29-2009 01:40 PM

For Fun: Have a Unix time party
 
Hi there. I didn't really know where to put this exactly, just sharing with the world, looking for improvements...

You may not have realised (though you probably have) that unix time 1234567890 (seconds since the epoch) is nearly upon us. This is a small script which counts down the seconds to this event.

Code:

#!/bin/bash
# unixparty - a countdown script

secs=$[1234567890-`date +%s`]

while [ $secs -gt 0 ]
do
clear

echo
echo " Seconds until UNIX time 1234567890"
echo

secs=$[1234567890-`date +%s`]
echo "    seconds: $secs"
mins=$[$secs/60]
echo "    minutes: $mins"
hrs=$[$mins/60]
echo "    hours:  $hrs"
days=$[$hrs/24]
echo "    days:    $days"
sleep 1
done
echo
echo
echo "    HAPPY UNIX 1234567890 second!!!"
echo
echo

My question? Can anyone improve upon this since it has a number of shortfalls.
1) It scrolls using the clear command
2) The sleep mechanism isn't entirely reliable (appears to hang for ~2 secs).

I look forward to hearing your replies, though I'm sorry if you've read this and feel I've wasted your time! (It is perhaps a bit purile!)

Matt

crabboy 01-30-2009 10:08 AM

not sure what the significance is, but here is an improvement to your script:
Code:

clear
while [ $secs -gt 0 ]
do
  tput cup 0 0


ncsuapex 01-30-2009 10:14 AM

HA! 1234567890 is on the day of my brothers birthday! He's about the most incompetent computer user there is though.

mmatt 01-31-2009 06:57 PM

Thanks crabboy, I'll give that a try. Planning on having it on a big screen in the lab perhaps. :)

ilikejam 02-04-2009 05:35 PM

New! (slightly) Improved!
 
Code:

#!/bin/bash

OMG=1234567890

T=`date +%s`
if [ $T -ge $OMG ]
then
    echo "Too late."
    exit 1
fi

trap "printf \"\r\"; echo \"Awww, booo!                              \"; exit 2" SIGINT SIGHUP

S=2
while [ $S -gt 1 ]
do
    T=`date +%s`
    S=$(($OMG-$T))
    M=$(($S/60))
    H=$(($M/60))
    D=$(($H/24))
    SL=$(($S-$M*60))
    ML=$(($M-$H*60))
    HL=$(($H-$D*24))
    DL=$D
    printf "\r                                        "
    printf "\r$DL days, $HL hours, $ML minutes, $SL seconds"
    sleep 1
done

printf "\r"
echo "Wooooooooo!                              "


mmatt 02-05-2009 05:00 PM

Thanks
 
Even if it was for frivilous purposes, I've learnt new and useful ways of showing output on the command line so thanks for the feedback!

Matt

ncsuapex 02-13-2009 04:45 PM

Here's a countdown for ya!

http://www.1234567890day.com/

JOSEPH8 12-11-2010 02:49 AM

Unix time is a system for describing points in time, defined as the number of seconds elapsed since midnight proleptic Coordinated Universal Time not counting leap seconds. It is used widely, not only in Unix like operating systems, but also in many other computing systems and file formats.

devnull10 12-11-2010 11:15 AM

Quote:

Originally Posted by JOSEPH8 (Post 4187731)
Unix time is a system for describing points in time, defined as the number of seconds elapsed since midnight proleptic Coordinated Universal Time not counting leap seconds. It is used widely, not only in Unix like operating systems, but also in many other computing systems and file formats.

What is your point? And why drag up a post that is nearly 2 years old?

pwc101 12-11-2010 11:17 AM

Quote:

Originally Posted by devnull10 (Post 4187998)
What is your point? And why drag up a post that is nearly 2 years old?

Odds on they're about to start spamming LQ...

edit: Take a look at their signature: spam. I've reported them.


All times are GMT -5. The time now is 08:30 AM.