Operating System - HP-UX
1748183 Members
3580 Online
108759 Solutions
New Discussion юеВ

Progress Bar using shell script

 
SOLVED
Go to solution
ankitj1983
Frequent Advisor

Progress Bar using shell script

Hello All,

I have made a script to etact diskinformation using sympd list it usually takes 3-8 Mins depaing on disks & array size.

I want my script should display some progress bar like in Windows.is it possible to implement.

Thanks in advance.

Regards

Ankit
5 REPLIES 5
James R. Ferguson
Acclaimed Contributor

Re: Progress Bar using shell script

Hi Ankit:

One way to create a progress bar (dots, a spinning widget, etc.) in a shell script, is to build a function that paints the bar with small sleep intervals between each point. Launch this piece as a background task and capture its pid in a variable, like: TIMER=$!. Start your real work and when that's done, kill the background process that you first started (with 'kill ${TIMER}').

If you prefer, you can do your real work as a background process and let your progress bar or widget spin as a foreground task.

Regards!

...JRF...
ankitj1983
Frequent Advisor

Re: Progress Bar using shell script

Hi James,

Below is my script.
"EMC") echo "its OK"
ssh $srv /usr/symcli/bin/sympd list>/tmp/lun

echo "This is EMC"

echo "So we are extracting LUN ID'S"

while read inputline
do
lun=`cat /tmp/lun|grep $inputline|tr -s " "|cut -d " " -f2`
echo $lun>>disk_lun
echo $lun

done ssh eux290 -n /usr/symcli/bin/sympd list>/tmp/ankit >>>Time _insert_here

Can you bit explain as am running the command using ssh on another server so it will long to track the pid.

can we do time run until we get the control from ssh command.

Regards

Ankit


James R. Ferguson
Acclaimed Contributor
Solution

Re: Progress Bar using shell script

Hi (again) Ankit:

Here's an example:

# cat ./monitor
#!/usr/bin/sh
function show_progress
{
while true
do
echo ".\c";
sleep 1
done
}
function do_work
{
echo "...doing work\c"
sleep 15
echo "done!"
}
show_progress &
TIMER=$!
do_work
kill ${TIMER}
sleep 1
exit 0

Regards!

...JRF...
ankitj1983
Frequent Advisor

Re: Progress Bar using shell script

Hi James,

Thanks for your reply.

I understand your script.Can you tell me if run the below command this command executes around 10-15 Mins.

ssh eux290 -n /usr/symcli/bin/sympd list>/tmp/ankit

So on that time i want to display the time.

so how woild i do that ?
James R. Ferguson
Acclaimed Contributor

Re: Progress Bar using shell script

Hi (again) Ankit:

> I understand your script.Can you tell me if run the below command this command executes around 10-15 Mins.

> ssh eux290 -n /usr/symcli/bin/sympd list>/tmp/ankit

> So on that time i want to display the time.

If you want to report the elapsed number of seconds, you can do:

...
T0=${SECONDS}
ssh eux290 -n /usr/symcli/bin/sympd list>/tmp/ankit
echo "elapsed time = $((${SECONDS}-${T0})) seconds"
...

Regards!

...JRF...