18.118.210.213 |    

Navigation

Google Advertisement

This function display a progress process.

progress
  1. # **************************************************************
  2. # This function display a progress process.
  3. # To start the f_process function, you have to send the function
  4. # into the background. To stop the f_progress function, you have
  5. # to define the argument "stop".
  6. #
  7. # EXAMPLE:
  8. #
  9. #    echo -n "Starting some daemon "; f_progress &
  10. #    if sleep 10; then
  11. #       f_progress "stop"; echo -e "\t[ OK ]"
  12. #    else
  13. #       f_progress "stop"; echo -e "\t[ FAILED ]"
  14. #    fi
  15. #
  16.  
  17. function f_progress () {
  18.  
  19. local action=${1:-"start"}
  20. declare -a sign=( "-" "/" "|" "\\\\" )
  21.  
  22. # define singnal file...
  23. [ "$action" = "start" ] && echo 1 > /tmp/signal
  24. [ "$action" = "stop" ] && echo 0 > /tmp/signal
  25.  
  26. while [ "$( cat /tmp/signal 2>/dev/null )" == "1" ] ; do
  27.     for (( i=0; i<${#sign[@]}; i++ )); do
  28.         echo -en "${sign[$i]}\b"
  29.         # with this command you can use millisecond as sleep time - perl rules ;-)
  30.         perl -e 'select( undef, undef, undef, 0.1 );'
  31.     done
  32. done
  33.  
  34. # clear the last ${sign[$i]} sign at finish...
  35. [ "$action" = "stop" ] && echo -ne " \b"
  36.  
  37. }
Parsed in 0.002 seconds at 468.72 KB/s

Search
 
Full text search by name and content of a snippet.

User online
There are 3 users online.

Tags Cloud

Latest snippets
str2seconds
(Bash::Function)
is_integer
(Bash::Function)
file_rotate
(Bash::Function)
confirm
(Bash::Function)
is_workingtime
(Bash::Function)
last day of last month
(Bash::Snippets)
crypt_apr1_md5
(PHP::Function)
crypt_apr1_md5
(Perl::Function)
transparent
(CSS)
rfc2822Toiso8601
(PHP::Function)