User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Shell Scripting section within the Software Development category of DaniWeb, a massive community of 363,786 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,532 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Shell Scripting advertiser:
May 9th, 2007
Views: 1,747
Here is a little spinner thing for the command line, used when your current bash script is waiting on a background/system process.

The weird character is ^H or a backspace.
Last edited : May 9th, 2007.
bash Syntax
  1. ## This is similar to what FreeBSD does when it is booting
  2. ### some command &
  3. ### do_progress_spin_l $!
  4. # A small "asterik" like thing will spin until the process is complete
  5. #+ (when ps ax | grep PID no longer finds anything)
  6. do_progress_spin_l()
  7. {
  8. ## The characters to use
  9. # These will be overlapped via ^H
  10. ICON[0]="/"
  11. ICON[1]="-"
  12. ICON[2]="\\"
  13. ICON[3]="|"
  14.  
  15. ## The process we wish to monitor
  16. PROCESS=$1
  17.  
  18. ## Initialize count value
  19. # print out first icon
  20. icon_num=0
  21. echo -n ${ICON[$icon_num]}
  22.  
  23. ## While the process exists in ps ax, do this loop
  24. while ( ps ax | grep $PROCESS | grep -v "grep" 1>/dev/null )
  25. do
  26. ## If our count is bigger than 3 (our highest number icon)
  27. # reset it to 0
  28. if [ "$icon_num" -gt "3" ]; then
  29. icon_num=0
  30. fi
  31.  
  32. ## ^Hnew_icon
  33. echo -n ${ICON[$icon_num]}
  34. icon_num=`expr $icon_num + 1`
  35.  
  36. sleep 0.5
  37. # sleep 1
  38. done
  39.  
  40. ## Little clean-up. Print done and a new line
  41. echo -n "... Done"
  42. echo ""
  43. }
Comments (Newest First)
Stylish | Junior Poster in Training | May 9th, 2007
Wrong category issue was fixed. Hurrah!
Post Comment

Only community members can submit or comment on code snippets. You must register or log in to contribute.

DaniWeb Marketplace (Sponsored Links)
All times are GMT -4. The time now is 10:50 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC