Use shell scripts to simply simulate simultaneous read and write operations to specific files
Format of file contents:
Field1, Field2, field3, Field4
As a delimiter, but there are spaces.
- The script uses the following:
./check_write_read. SH Ten
Thu APR - +: -: -Cst .: Read Operation finished670Thu APR - +: -: -Cst .: Write Operation finished671Thu APR - +: -: $Cst .: Check Write okthu APR - +: -: AboutCst .: Check Read OK
if[[ $1=~ ^[1-9] ]]; ThenTimeInterval=$1Else Echo "parameter error, should be number"Exit1fitimefrom_1=`Date+%s ' timeto_1=`Expr$timefrom _1 +$timeInterval ' Timenow_1=$timefrom _1count_1=0timefrom_2=`Date+%s ' timeto_2=`Expr$timefrom _2 +$timeInterval ' timenow_2=$timefrom _2count_2=0functionrand () {min=1Max=292Num=$(Cat/dev/urandom |Head-NTen| Cksum |awk-F' ' '{print $}') Echo$ (($num% $max +$min))}functioncheckwrite () { whileRead Line Doresultmsg=`Catconfigdata.cfg |grep$LINE 'if[-Z"$RESULTMSG"-O"$RESULTMSG"==""-O X"$RESULTMSG"= = x]; Then Echo "Write Error" Echo "Line : $LINE" Echo "resultmsg: $RESULTMSG"Exit1 fi Done<Result_write.txtEcho "' Date ': Check Write OK"}functionCheckread () { whileRead Line Dolinenumber=`Echo$LINE |Cut-D:-F1 ' Linevalue=`Echo$LINE |Cut-D:-f2 |sedS/[[:space:]]//G 'Resultmsg= 'sed-N"$linenumber, 1p"configdata.cfg |awk-F',' 'begin{ofs= ","}{print $1,$2}'|sedS/[[:space:]]//G 'Resultmsg= 'sed-N"$linenumber, 1p"configdata.cfg |Cut-D,-f1,2|sedS/[[:space:]]//G ' if[-Z"$RESULTMSG"-O"$RESULTMSG"==""-O X"$RESULTMSG"= = x]; Then Echo "Read Error,it ' s null" Echo "linenumber: $linenumber" Echo "Linevalue: $linevalue" Echo "resultmsg: $RESULTMSG"Exit1 fi if["$RESULTMSG"!="$linevalue"]; Then Echo "Read Error,value error" Echo "resultmsg: $RESULTMSG" Echo "Linevalue: $linevalue"Exit1 fi #Echo "resultmsg: $RESULTMSG" #Echo "Linevalue: $linevalue" Done<Result_read.txtEcho "' Date ': Check Read OK"}#WriteOperationfunctionwriteoperation () {RM-F result_write.txtuntil["$timenow _1"=="$timeto _1" ] Dornd_1=$(Cat/dev/urandom |Head-NTen| Cksum |awk-F' ' '{print $}') Echo "${rnd_1}">>Result_write.txtEcho "${rnd_1}">>configdata.cfg count_1=`Expr$count _1 +1' Timenow_1=`Date+%s ' Done Echo "$count _1"|Tee-a result_write.txtEcho "' Date ': Write operation finished"} #read Actionfunctionreadoperation () {RM-F result_read.txtuntil["$timenow _2"=="$timeto _2" ] Dornd_2=' Rand ' line="${rnd_2}"":""' Sed-n"$rnd _2,1p"configdata.cfg | cut-d,-f1,2 '" Echo$line >>result_read.txt timenow_2=`Date+%s ' Done Echo "' Date ': Read operation finished"} {writeoperation}&{readoperation}&wait#sleeptime=`Expr$timeInterval +2`#Sleep$sleeptimeCatResult_write.txt |WC-L |TeeCheckwritecheckreadexit0
Use shell scripts to simply simulate simultaneous read and write operations to specific files