Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to make a "progress bar" ? 1

Status
Not open for further replies.

TSch

Technical User
Jul 12, 2001
557
DE
Hi folks,

I'm trying to write a little "progress bar" that's supposed to write a dot every second a certain process is running.

Something like:

Reading Server Status .
sleep 1 second
Reading Server Status ..
sleep 1 second
Reading Server Status ...
and so on

After the process is finished I want the $? output to be interpreted as either "ok" or "error" and put that at the end of the line. Like this:

Reading Server Status ....... error

Right now I only found a way to append a dot to the "Reading Server Status" line every second. Problem is, that I can only write a certain number of dots, AFTER that execute the process and AFTER the process finishs put an "ok" or an "error" at the end of the line. Like this:

---------------------------------------------
echo "Testing Server Status:"
sleep 2
echo "Status is \c"
sleep 1
echo ".\c"
sleep 1
echo ".\c"
sleep 1
echo ".\c"
echo ${MOJB[*]} | nohup su - ita -c "nohup testprogram" | grep "statusline" > /dev/null
if [ $? = 0 ]
then
echo " ok"
else
echo " error >"
exit
fi
---------------------------------------------

How can I change this so that the dots are being added every second AS LONG AS THE PROCESS IS RUNNING ?

Any ideas ?

Regards
Thomas
 
Hi

Magic word : background.
Code:
#!/usr/bin/ksh

function progdo
{
  while :; do
    echo ".\c"
    sleep 1
  done
}

echo "Testing Server Status:"

progdo &
progpid=$!

find / > /dev/null

kill $progpid

echo "Ok"
echo "Testing done."
Tested with (pd)[tt]ksh[/tt].

Feherke.
 
That's great !!!

Exactly what I was looking for :)


Thanks a lot !

Regards
Thomas
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top