Operating System - HP-UX
1829901 Members
2963 Online
109993 Solutions
New Discussion

Display time which loops?

 
SOLVED
Go to solution
Chua Wen Ching
Regular Advisor

Display time which loops?

How to make the current time loops in UNIX? I had done it in Cobol but i do not know whether bourne shell script can do that? Is it possible HP-UX 10.20 can perform such thing. What i meant is similar to (in windows 2000 taskbar on the right corner you can see the time running)? Any sample bourne shell script?
wenching
15 REPLIES 15
Pete Randall
Outstanding Contributor

Re: Display time which loops?

xclock -digital -update 1

Pete

Pete
Chua Wen Ching
Regular Advisor

Re: Display time which loops?

My org uses a dumb terminal only monochrome monitors and keyboards. The HP-UX 10.20 XWindows is not configured. There is not Windows GUI. That is why i want to create the time loop using bourne shell script. Thank you for your help. Is there other solutions?
wenching
harry d brown jr
Honored Contributor

Re: Display time which loops?

#!/usr/bin/ksh
#
while [ "1" = "1" ]; do
sleep 15
date
done

Change the sleep 15 to your desired sleep time.

live free or die
harry
Live Free or Die
Chua Wen Ching
Regular Advisor

Re: Display time which loops?

Is there any sample on bourne shell rather than korn, perl or c?
Base on the output i get:
(i change sleep 1)
Mon Oct 14 19:28:35 SST 2002
Mon Oct 14 19:28:36 SST 2002
Mon Oct 14 19:28:27 SST 2002

Is it possible if my time looks like this:

Previous
--------
19:28:01

Current
--------
19:28:02 (1 is replace by 2 - the cursor is at 2)

I do not want it to go to the next line. If i keep refresh the screen, will it increase the uptime and slow down my application.

Can i refresh only a portion of a screen rather than the whole screen.

Thank you.

wenching
harry d brown jr
Honored Contributor
Solution

Re: Display time which loops?

#!/usr/old/bin/sh
#
while [ "1" = "1" ]; do
tput cup 22 50
date
sleep 5
done


live free or die
harry
Live Free or Die
Bill Hassell
Honored Contributor

Re: Display time which loops?

In the simplest form:

#!/usr/bin/sh
# Show time of day
while :
do
date
sleep 1
done

---

This shows the timer/date every second. Probably not what you want. You most likely want it to appear in some corner of your display, sort of like Windows. This is where tput will come in handy:

#!/usr/bin/sh

# Show time of day in upper right corner

set -u
PATH=/usr/bin
UR=$(tput cup 0 60)
while :
do
# various date/time formats, last one wins
MYDATE=$(date '+%R')
MYDATE=$(date '+%a %R')
MYDATE=$(date)
LEN=${#MYDATE}
START=$((COLUMNS-LEN-2))
UR=$(tput cup 1 $START)
echo "$UR$(tput bold) $MYDATE $(tput sgr0)"
sleep 1
done

---

Now this script allows you to change the date format (3 examples are shown) and it will calculate how to position the string on the screen. I've added the bold enhancement to make the string stand out.

This is a bit impractical since when you run it, the time/date is show OK but you can't do anything except watch the script run. If you put it in the background, it will fail because a background process is trying to write to an active terminal.

What you want is very complicated for a standard terminal. Each time you run vi or other programs, this date program will mess up the screen. And just listing files in the shell will scroll the upper right corner off the top of the screen. But it does demonstrate how you can use tput and the Curses library.


Bill Hassell, sysadmin
Robin Wakefield
Honored Contributor

Re: Display time which loops?

Hi,

Try this:
============================
#!/bin/sh

while :;do
echo `date "+%H:%M:%S"` '\b\b\b\b\b\b\b\b\b\c'
sleep 1
done
=============================

Rgds, Robin
Chua Wen Ching
Regular Advisor

Re: Display time which loops?

Wow...it works pretty smooth. I got 1 question, as you can see when display the time loop in my application, and at the same time i ask the user to enter an input. Will my cursor pointed at my input or at the time. Because everytime the time loops my cursor will be at the time. Just additional knowledge? Thank you.
wenching
Dietmar Konermann
Honored Contributor

Re: Display time which loops?

Just another idea if you are using 2392/hpterm compatible terminals...

if [[ "$-" = *i* && ( "$TERM" = hp* || "$TERM" = *2392* ) ]]; then
while sleep 1; do
clock=$(/usr/bin/date "+%H:%M:%S")
echo "\033&f0a8k8d0L$clock\c"
echo "\033&jB\c"
done &
fi

This writes the time to the field.

Regards...
Dietmar.
"Logic is the beginning of wisdom; not the end." -- Spock (Star Trek VI: The Undiscovered Country)
Chua Wen Ching
Regular Advisor

Re: Display time which loops?

Hmm...sound complicated? How do i know what kind of terminal i using. I saw the monochrome monitor brand WYSE. Don't know and never heard before. I think we are using VT100. Is it similar to the terminal type you refering to?
wenching
Dietmar Konermann
Honored Contributor

Re: Display time which loops?

Unfortunately not... the 2392 terminals have a dedicated status/function key area at the bottom. You can use that area without disturbing the rest of your screen....

Regards...
Dietmar.
"Logic is the beginning of wisdom; not the end." -- Spock (Star Trek VI: The Undiscovered Country)
John Meissner
Esteemed Contributor

Re: Display time which loops?

loop=1
while [ $loop = 1 ]
do
clear
date | awk '{print $4}'
sleep 1
done
All paths lead to destiny
Chua Wen Ching
Regular Advisor

Re: Display time which loops?

Dear Dietmar Konermann, does the function key at the bottom of the terminal looks like keysh. Anyway no one yet had answer my question on if my application running the time loop and at the same time, i want the user to input data. Will the cursor point to my input or the time(loops)? Thank you.
wenching
John Meissner
Esteemed Contributor

Re: Display time which loops?

do you want to display the time in the PS1? (the prompt)?
All paths lead to destiny
Chua Wen Ching
Regular Advisor

Re: Display time which loops?

I think i know how to display date in my PS1. I think must specify the date command. Anyway no one yet had answer my question. If i run the time loop and also ask the end user to enter some inputs on the same time, can it be done? I tried to add some echo and read command at the end of the time loop script, but i only manage to see the time but no echo message and read. Any solutions? Thank you.
wenching