Tuesday, October 6, 2015

Linux: Timer script

最近找到了一個在linux 中跑timer的script...這是隔X秒打印文件行數的script...

#!/bin/ksh

if [ $# -eq 0 ]
then
echo "Usage: $0 [display_seconds] [command]"
else
time=$1
time="${time:-1}"
shift
while (true); do
  date
eval $@
  echo "run at $(date)" 
sleep $time
wait
done;
fi

用法是sh timer.sh [秒數] [檔案+]

可以輸入多個檔案,會執行裏面的wc -l file指令....當然改掉這個就可以做其他事情了~

Reference: 60 second Timer with Shell Script

No comments: