Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 16th, 2012  |  syntax: None  |  size: 0.55 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/bin/bash
  2.  
  3. usage() {
  4.   echo "usage:  `basename $0` [-n secs] command"
  5. }
  6.  
  7. if [ $# -eq 0 ]
  8. then
  9.   usage
  10.   exit 1
  11. fi
  12.  
  13. seconds=2
  14.  
  15. while getopts "n:" opt
  16. do
  17.   case $opt in
  18.     n)
  19.       seconds=$OPTARG
  20.       shift $(($OPTIND - 1))
  21.       ;;
  22.     *)
  23.       usage
  24.       exit 1
  25.       ;;
  26.   esac
  27. done
  28.  
  29. command=$1
  30.  
  31. while [ 1 ]
  32. do
  33.   res=$(eval $command)
  34.   time=$(date "+%a %b %e %T %Y")
  35.   cols=$(tput cols)
  36.   part=$(printf "Every %ss: %s " "$seconds" "$command")
  37.   just=$(($cols - ${#part}))
  38.   clear
  39.   printf "%s%*s\n\n%s\n" "$part" $just "$time" "$res"
  40.   sleep $seconds
  41. done