linux执行脚本执行100次,linux shell 控制脚本执行次数

下面是俺写的测试脚本,为了能运行多次测试程序性能,想控制运行个数,通过lockfile 和 grep配合进行限制。

#!/bin/bash . /etc/profile project=simnin export CLASSPATH=.:/usr/$project:$CLASSPATH for jarfile in /usr/$project/lib/*.jar ; do if ! echo $CLASSPATH | grep $jarfile > /dev/null then   export CLASSPATH=$CLASSPATH:$jarfile fi done #echo $# #echo $* #echo $0 $1 $2 $3 #run once when lock file lckfile="/tmp/.perfomanceTest.lck" lockfile -1 -r 60 $lckfile log=/tmp/perftest.log echo >> $log lmt=1 if [ "`date +%H`" -lt 8 -o "`date +%H`" -gt 18 ]; then   lmt=10 fi prog="com.lj.PerformanceTest" ps -ef | grep $prog | grep "grep $prog" -v >>$log cnt=`ps -ef | grep $prog | grep "grep $prog" -v -c ` if [ "$cnt" -gt "$lmt" ]; then   rm -f $lckfile   echo "exit 1 when $cnt > $lmt ." >>$log   exit 1; fi echo "$$ start at `date`" >>$log #echo =====================ENV============== >>$log #env >>$log echo =====================CMD============== >>$log echo $0 $* >> $log $JAVA_HOME/bin/java com.lj.PerformanceTest $* >>$log 2>&1  & rm -f $lckfile echo "$$ $! is running" >>$log echo "$$ end at `date`" >>$log

你可能感兴趣的:(linux执行脚本执行100次)