Use shell scripts to simply simulate simultaneous read and write operations to specific files

Source: Internet
Author: User


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

    • Output Result:

Thu APR -  +: -: -Cst .: Read Operation finished670Thu APR -  +: -: -Cst .: Write Operation finished671Thu APR -  +: -: $Cst .: Check Write okthu APR -  +: -: AboutCst .: Check Read OK

    • Script content:
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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.