watch 명령 실행

1116 단어
#!/bin/sh
# watch-like program
# ==================================================
# Version      Author        Date       Description
# 0.1           April Lee    2014-03-27 initial
# ==================================================


echo "watch program"
echo "USAGE:"
echo "`basename ${0}` -t time -l lines -c commands"
echo "every 'time' to reflash; default is 2s"
echo "only show 'lines' lines; default is 10 "
echo "watch the 'commands'; default ls command"
echo 


DATAFORMAT="%y-%m-%d %H:%M:%S"


while getopts t:c:l: opt
do
    case "$opt" in
        t) SLEEPTIME=$OPTARG;;
        c) CMD=$OPTARG;;
        l) SHOWLINES=$OPTARG;;
    esac
done

: ${SLEEPTIME:=2} ${CMD:="ls"} ${SHOWLINES:=10}


while : 
do
    clear 
    echo "Every $SLEEPTIME s   $PWD  `date +"$DATAFORMAT"`"
    # exec $CMD |  sed -n "p" #awk 'for(i=0; i<10; i++){print $0}'
    eval $CMD |  awk '{if(NR <= '$SHOWLINES'){print $0}}'
    sleep $SLEEPTIME
done

좋은 웹페이지 즐겨찾기