LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-30-2003, 01:45 PM   #1
zael
LQ Newbie
 
Registered: Aug 2003
Posts: 26

Rep: Reputation: 15
Progress Bar


Does anyone know how i can give the effect of a progress bar in a Linux Script while running a process?


Thanks!
 
Old 09-30-2003, 04:17 PM   #2
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
Here are two hacks at what you are looking for:

The first will call the process (in my test case a sleep) and print # marks every second until the process ends. This bar really only gives the user a hint that something is still working. He/she has no clue how long it will take.
Code:
#!/bin/sh

sleep 8&  # put the calling processes here
PROCPID=$!

while [ 1 ]; do
   sleep 1
   ps -ef | grep $PROCPID | grep -vq grep
   if [ $? -eq 1 ]; then
      break;
   else
      echo -n "#"
   fi
done
This second attempt will display hash marks from 0% to 100%. The trick here it to know about how long the process will take. If it consistently takes about 10 seconds then add it to the AVG_TIME var. If you have no clue how long it will take then you probably should use the script above.
Code:
#!/bin/sh

COUNT=0
AVG_TIME=5

STEP=`expr 50 / $AVG_TIME`
echo    "           |0%--------------------50%---------------------100%|"
echo -n "Progress:   "
while [ $COUNT -lt $AVG_TIME ]; do
   sleep 1
   HASH=0
   while [ $HASH -lt $STEP ]; do
      echo -n "#"   
      HASH=`expr 1 + $HASH`
   done
   COUNT=`expr 1 + $COUNT`
done
 
Old 10-01-2003, 06:12 AM   #3
UltimaGuy
Member
 
Registered: Aug 2003
Location: Chennai, India
Distribution: PCLinuxOS .92, FC4
Posts: 840

Rep: Reputation: 32
Well, that was a cool one crabboy. I am very much impressed by this one.
 
Old 10-01-2003, 12:20 PM   #4
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
Another way to do it is spawn a process that loops and updates the display based on the contents of a file and then dies when the file contains certain text eg "STOP". The actual program that is doing the work can then echo the makers eg #s to the file at strategic points in the process.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bootsplash - progress bar - not working depi Linux - General 2 08-13-2007 05:26 AM
cp with progress bar? Rotwang Linux - General 5 04-27-2005 07:49 PM
Progress bar image craigs1987 Fedora 0 05-27-2004 02:31 PM
cp: progress bar chii-chan Linux - General 2 10-30-2003 06:30 PM
lol slackware progress bar... roofy Slackware 2 05-07-2003 08:39 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:33 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration