Skip to content

Instantly share code, notes, and snippets.

@bonifaido
Created September 8, 2011 11:45
Show Gist options
  • Save bonifaido/1203220 to your computer and use it in GitHub Desktop.
Save bonifaido/1203220 to your computer and use it in GitHub Desktop.
Watch for Solaris
#!/bin/bash
usage() {
echo "usage: `basename $0` [-n secs] command"
}
if [ $# -eq 0 ]
then
usage
exit 1
fi
seconds=2
while getopts "n:" opt
do
case $opt in
n)
seconds=$OPTARG
shift $(($OPTIND - 1))
;;
*)
usage
exit 1
;;
esac
done
command=$1
while [ 1 ]
do
res=$(eval $command)
time=$(date "+%a %b %e %T %Y")
cols=$(tput cols)
part=$(printf "Every %ss: %s " "$seconds" "$command")
just=$(($cols - ${#part}))
clear
printf "%s%*s\n\n%s\n" "$part" $just "$time" "$res"
sleep $seconds
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment