LinuxQuestions.org
Help answer threads with 0 replies.
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 01-07-2011, 03:51 AM   #1
frater
Member
 
Registered: Jul 2008
Posts: 106

Rep: Reputation: 23
can someone improve my progress indicator?


I created a script to flush my sendmail to another mailserver. Because it takes some time I want to give some simple feedback using a rotating bar.


Code:
echo -n "Processing mailq: -"
n=1
while [ $n -lt 30 ] ; do
  .....  do something
  let n+=1
  char='-'
  [ `expr $n % 2` -eq 1 ] && char='|'
  echo -en "\010${char}"
done
echo -e "\010done"
I'm convinced this can be done much nicer with 'awk' and printf, but somehow awk makes me dazzle..
Albeit a bit clumsy, this does the job.

Even if you know an even better way to give feedback, I would still like to see an awk equivalent (and the better way).

Thanks in advance
 
Old 01-07-2011, 04:29 AM   #2
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,437

Rep: Reputation: 1879Reputation: 1879Reputation: 1879Reputation: 1879Reputation: 1879Reputation: 1879Reputation: 1879Reputation: 1879Reputation: 1879Reputation: 1879Reputation: 1879
Well the first thing would obviously be to change the loop so it references the task that is happening instead of a counter (but I assume you know this).
bash:
Code:
#!/bin/bash

spinner=( "/" "-" "\\" "|" )

for (( x = 0; x <= 30; x++ ))
do
    echo -ne "\b${spinner[x%4]}"
    sleep 0.1
done
awk:
Code:
awk 'BEGIN{cmd="sleep 0.1"; split("/ - \ |",spinner);for(x=0;x<=30;x++){printf "\b%s",spinner[x%4+1];system(cmd)}}' 2>/dev/null
I put the redirect in as awk complains about the escape (someone else might know how to stop that )

You can also move away from a spinner and go for (x)dialog to generate a progress bar, same concept
 
  


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
md5sum progress indicator Ianmcc Linux - Software 3 02-04-2009 02:50 PM
gui file copy progress indicator? zero79 Linux - Software 3 07-10-2005 02:00 AM
Loss of scp progress indicator when piping command to tee Arodef Linux - General 1 03-08-2005 09:01 PM
cp command with progress indicator exodist Linux - Software 1 07-21-2004 06:27 PM
bash: How can I create a progress indicator? apeekaboo Programming 5 06-27-2003 10:41 AM


All times are GMT -5. The time now is 09:44 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration