1835085 Members
2530 Online
110073 Solutions
New Discussion

Scripting question

 
SOLVED
Go to solution
Adam Noble
Super Advisor

Scripting question

Hi all,

This is quite an obscure question but would love to know how to do this. If I am writing a script which is interactive I want to show that the script is processing at certain points. In otherwords for example the script will say "Gathering Info....." what I wanted to know is how can I show the script is processing such as adding an additional dot every 10 secs. I hope this makes sense.

Cheers
4 REPLIES 4
Steven E. Protter
Exalted Contributor
Solution

Re: Scripting question

Shalom,

while true
do
echo .
sleep 10
done


Lots of ways to do this.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
James R. Ferguson
Acclaimed Contributor

Re: Scripting question

Hi Adam:

To create a progress bar (dots, a spinning widget, etc.) in a shell script, you build a function that paints the bar with small sleep intervals between each point. You launch this piece as a background task while processing to do the real work of your script. When the real work is done, you kill the background process having captured its pid when you launched it.

Regards!

...JRF...
Dennis Handly
Acclaimed Contributor

Re: Scripting question

You could do the reverse of JRF's solution and put the process the that does the work in the background and use SEP's sleep echo ".\c" to print out the dots.
You can use "kill -0 $SAVE_PID" (where you saved $! from the background job) to know when to quit the loop.
Hein van den Heuvel
Honored Contributor

Re: Scripting question

If you add a script to output dots then all you are showing is that the script outputting dots is making good progress at doing nothing.
If that helps your end users feeling better about the system, then fine.
Personally I would want to see honest progress otherwise I still need to resort to top or ps | grep to 'see' that it might be working.
Maybe a dot for each 10O MB processed? Or every 100 files compiled, every 1000 primes calculated, every 10,000 IOs does, every 5 seconds CPU burned, or whatever the task on hand might be

fwiw,
Hein.