µ±Ç°Î»ÖãºLinux½Ì³Ì - Linux×ÊѶ - Ò»¸ö Shell ³ÌÐòµÄÐÔÄÜÓÅ»¯

Ò»¸ö Shell ³ÌÐòµÄÐÔÄÜÓÅ»¯

    ±àд Linux Shell ½Å±¾³ÌÐò²»Òª½öÏÞÓÚÍê³É»ù±¾µÄ³ÌÐò¹¦ÄÜ£¬ÈÏÕæµÄ·ÖÎö Shell ½Å±¾²¢ÕÒ³öÓÅ»¯µÄ·½·¨¶Ô¸öÈËÄÜÁ¦µÄÌá¸ßÒÔ¼°¶Ô½Å±¾³ÌÐòµÄÖÊÁ¿¸ÄÉƶ¼ÓÐÖØÒªµÄÒâÒ壬ϣÍû¶ÁÕßÄÜ´Ó±¾ÎÄÖлñµÃÐí¶àʵÓÃµÄ Shell ³ÌÐò·½·¨¡£

±¾ÎÄ Shell ³ÌÐòÔËÐл·¾³£º

³ÌÐòÔËÐл·¾³ Redhat Linux As3 GNU bash, version 2.05b.0(1)-release (i386-redhat-linux-gnu) ´úÂëÇåµ¥£ºshellcode.txt

    ÎÊÌâÃèÊö£ºÓÐÒ»¸öÆÕͨµÄͨ»°»°µ¥Îļþ(°üÀ¨"¼Æ·ÑºÅÂë"£¬"Ö÷½ÐºÅÂë"£¬"±»½ÐºÅÂë"£¬"¿ªÊ¼Ê±¼ä"£¬"½áÊøʱ¼ä"£¬"ʱ³¤"£¬"·ÑÓÃ"µÈÆäËü×Ö¶Î)£¬ÒªÇó¸ù¾ÝÁíÍâÒ»¸öºÅ¶ÎÅäÖÃÎļþ(ÓÉ"ºÅ¶ÎÏÂÏÞ"ºÍ"ºÅ¶ÎÉÏÏÞ"Á½¸ö×Ö¶Î×é³É)½«´Ë»°µ¥Îļþ½øÐзּð¹ýÂÇ¡£

·Ö¼ð¹æÔò£ºÈç¹ûͨ»°»°µ¥ÎļþÖеÄ"¼Æ·ÑºÅÂë"λÓںŶÎÎļþµÄij¸öºÅ¶ÎÄÚ£¬Ôò½«´ËÌõ¼Ç¼¼ÆÈë½á¹ûÎļþ 1£¬·ñÔò¼ÆÈë½á¹ûÎļþ 2¡£

ͨ»°»°µ¥ÎļþÑùÀý£º

901332000390133200039918128025200608141634202006081416345030200001005 992664520899266452089918188065200608141634152006081416354590300001005 9934877207993487720799369720032006081416362020060814163930190500001005 ...... ......

ºÅ¶ÎÅäÖÃÎļþÑùÀý£º

9013305000,9013327999 9013767000,9013768999 9923670000,9923679999 9928998000,9928999999 9932310000,9932319999 9932333400,9932333599 9936034000,9936036999 9936084000,9936084999 9998537000,9998537999 9998620000,9998629999 9998690000,9998699999

ÀýÈ磺

    ¶ÔÓÚͨ»°»°µ¥ÎļþµÄµÚÒ»Ìõ¼Ç¼ÖеÄ"¼Æ·ÑºÅÂë"Ϊ 9013320000£¬´ËºÅÂëÕýºÃÊôÓںŶÎÅäÖÃÎļþµÄµÚÒ»¸öºÅ¶Î 9013305000,9013327999ÖУ¬¼´£ºÌõ¼þ 9013305000<= 9013320000 <=9013327999 ³ÉÁ¢£¬ËùÒÔÓ¦¸Ã½«Í¨»°»°µ¥ÎļþµÄµÚÒ»Ìõ¼Ç¼¼ÆÈë½á¹ûÎļþ 1 ÖУ»¶ÔÓÚͨ»°»°µ¥ÎļþÖеĵڶþÌõ¼Ç¼µÄ"¼Æ·ÑºÅÂë"Ϊ 9926645208 Ëü²»ÊôÓںŶÎÎļþÖеÄÈκÎÒ»¸ö¶Î£¬ËùÒÔÓ¦¸Ã½«Í¨»°»°µ¥µÄµÚ¶þÌõ¼Ç¼¼ÆÈë½á¹ûÎļþ 2 ÖС£

¶ÔÓÚÕâÑùÒ»¸ö¼òµ¥µÄÎÊÌâÊ×ÏÈÏëµ½µÄ½â¾ö·½·¨Îª£º

½â¾ö·½·¨1£º

    дһ¸öË«ÖØÑ­»·£¬Íâ²ãÑ­»·ÎªÖðÌõ¶ÁÈ¡"ͨ»°»°µ¥Îļþ"²¢»ñȡÿÌõ¼Ç¼µÄµÚÒ»¸ö×ֶεÄÖµ"¼Æ·ÑºÅÂë"£¬ÄÚ²ãÑ­»·£º¸ù¾ÝÍâ²ãÑ­»·»ñµÃµÄ"¼Æ·ÑºÅÂë"ÔÚ"ºÅ¶ÎÎļþ"ÖÐÑ­»·±È½Ï£¬Åжϴ˺ÅÂëÊÇ·ñÊôÓÚÏàÓ¦ºÅ¶Î¡£

³ÌÐò´úÂëÈçÏÂ(Ê¡ÂÔÁËÎļþ´æÔÚÐÔÅжϵÈÓï¾ä)£º

while read f do org="$(eXPr substr ${f} 1 10)" #È¡µÃ"¼Æ·ÑºÅÂë"´æÈë±äÁ¿orgÖÐ while read numseg do nglow="$(expr substr ${numseg} 1 10 )" #½«ºÅ¶ÎÏÂÏÞ´æÈë±äÁ¿nglow ngtop="$(expr substr ${numseg} 12 10 )" #½«ºÅ¶ÎÉÏÏÞ´æÈë±äÁ¿ngtop if [ "$org" \> "$nglow" -a "$org" \< $ngtop ] #ÅжÏ"¼Æ·ÑºÅÂë"ÊÇ·ñÔڴ˺ŶÎÄÚ then echo "${f}" >> ./resultfile1.cdr #Èç¹ûÔڴ˺ŶÎÄÚ£¬½«´Ë¼Ç¼¼ÆÈë½á¹ûÎļþ1ÖÐ else echo "${f}" >> ./resultfile2.cdr #Èç¹û²»Ôڴ˺ŶÎÄÚ£¬½«´Ë¼Ç¼¼ÆÈë½á¹ûÎļþ2ÖÐ fi done < ./numseg.txt done < ./rttest.txt

    ½â¾ö·½·¨1 ¶ÔÓںŶÎÎļþºÍͨ»°»°µ¥µÄ¼Ç¼Êý¶¼±È½ÏÉÙµÄÇé¿öÏ»ù±¾¿ÉÒÔÍê³É¹¤×÷£¬µ«Êǵ±Á½¸öÎļþµÄ¼Ç¼Êý½Ï¶à(ÀýÈçºÅ¶ÎÎļþ>50Ìõ£¬»°µ¥Îļþ> 10000Ìõ)µÄʱºò£¬ÕâÖÖ·½·¨¾Í»á»¨·Ñ¼¸¸öСʱÉõÖÁ¼¸ÌìµÄʱ¼ä²ÅÄܵóö´¦Àí½á¹û¡£´Ë½Å±¾³ÌÐòÖ´ÐÐÂýµÄÔ­ÒòÊǶԵڶþ¸öÑ­»·ÄڵıȽÏÔËËãÖ»ÓÃÁË×î¼òµ¥µÄ˳Ðò±È½Ï·½·¨£¬ËùÒÔµ±ºÅ¶ÎÎļþµÄ¼Ç¼Ôö¶àµÄʱºò£¬½Å±¾µÄÖ´ÐÐËٶȻἱ¾çϽµ¡£

 

½â¾ö·½·¨2£º

½«ÄÚ²ãÑ­»·µÄÖð¸ö±È½ÏµÄ·½·¨¸ÄΪ¶þ·Ö²éÕÒ·¨½øÐÐÅжϣ¬³ÌÐò´úÂëÈçÏ£º

#!/bin/bash #Author Xsh date:08-15-2006 ££³ÌÐòÖÐʹÓÃÁ˶þ·Ö²éÕÒ·¨½øÐкÅÂëµÄ·¶Î§ÅÐ¶Ï ££ÎªÍ»³öÖص㣬ʡÂÔÁËÎļþ´æÔÚÐÔÅжϺÍÒì³£²¶»ñÒÔ¼°°ïÖúÌáʾµÈ³ÌÐòÓï¾ä ££³ÌÐòµÄ¹¤×÷Ŀ¼Ϊµ±Ç°Ä¿Â¼ echo "Time:$(date)==>Strat to processing........." #ÏÔʾ³ÌÐò¿ªÊ¼ÔËÐÐʱ¼ä while read numseg do tmplow="${tmplow} $(expr substr ${numseg} 1 10 & >/dev/null ) " tmptop="${tmptop} $(expr substr ${numseg} 12 10 & >/dev/null ) " done < ./numseg.txt #¶ÁÈ¡ºÅ¶ÎÎļþ£¬ÏÂÏ޺ŶδæÈë±äÁ¿tmplow£¬ÉÏÏ޺ŶδæÈë±äÁ¿tmptop arr_lownug=(${tmplow}) #½«ÏÂÏ޺ŶδæÈëÊý×éarr_lownug arr_topnug=(${tmptop}) #½«ÉÏÏ޺ŶδæÈëÊý×éarr_topnug #¶¨Ò庯Êýchecknum()£¬ÊäÈë²ÎÊýΪÐèÒª¼ì²éµÄ"¼Æ·ÑºÅÂë"£¬Êä³ö²ÎÊýΪ0»òÕß1 #Èôchecknum()Êä³öΪ0 ±íʾ"¼Æ·ÑºÅÂë" ²»ÔںŶÎÎļþµÄËùÓкŶη¶Î§ÄÚ #Èôchecknum()Êä³öΪ1 ±íʾ"¼Æ·ÑºÅÂë" ÔںŶÎÎļþµÄËùÓкŶη¶Î§ÄÚ # checknum()º¯ÊýÖÐÓöþ·ÖËÑË÷·¨½øÐкÅÂëµÄÅÐ¶Ï checknum(){ thisnum=$1 ckresult=0 lowflag=0 topflag=$(expr ${#arr_lownug[*]} - 1 ) #±ê×¢1 MaxIndex=$(expr ${#arr_topnug[*]} - 1 ) #±ê×¢2 midflag=0 midflag=$(expr ${topflag} / 2 ) #±ê×¢3 if [ "${thisnum}" \< "${arr_lownug[0]}" -o "${thisnum}" \> "${arr_topnug[${MaxIndex}]}" ] then return 0 else while [ "$lowflag" != "$midflag" ] do if[ "$thisnum" \> "${arr_lownug[${midflag}]}" -o "$thisnum" == \ "${arr_lownug[${midflag}]}" ] then lowflag=${midflag} midflag=$(expr `expr ${topflag} + ${lowflag}` / 2 ) #±ê×¢4 elif["$thisnum"\<"${arr_lownug[${midflag}]}" -o "$thisnum" == \ "${arr_lownug[${midflag}]}" ] then topflag=${midflag} midflag=$(expr `expr ${topflag} + ${lowflag}` / 2 ) #±ê×¢5 else echo "Error!" fi done if [ "$thisnum" \< "${arr_topnug[${lowflag}]}" -o "$thisnum" == \ "${arr_topnug[${lowflag}]}" ] then return 1 else return 0 fi fi }££º¯Êý¶¨ÒåÍê±Ï while read f do org="$(expr substr ${f} 1 10)" #±ê×¢6 checknum ${org} returnval=$? if [ "$returnval" == "1" ] then echo "${f}" >> ./Match_result.cdr #½«Æ¥ÅäµÄ¼Ç¼´æÈë½á¹ûÎļþ1 else echo "${f}" >> ./NoMatch_result.cdr #½«²»Æ¥ÅäµÄ¼Ç¼´æÈë½á¹ûÎļþ2 fi done < ./rttest.txt echo "Time:$(date) ==> Proccess is end! " exit 0;

    ½«ÒÔÉϳÌÐòͶÈëÔËÐУ¬ºÅ¶ÎÎļþÓÐ 71ÐмǼ£¬ÐèÒª·Ö¼ðµÄͨ»°»°µ¥Îļþ17 ÍòÌõ×óÓÒͨ¹ý¹Û²ì·¢ÏÖ´Ë·½·¨µÄÖ´ÐÐЧÂÊȷʵ±È½â¾ö·½·¨1 Ìá¸ßÁ˺ܶ࣬µ«ÊÇÈÔÐèÒªÊýСʱµÄʱ¼ä²ÅÄÜÖ´ÐÐÍê±Ï¡£ÎÒÁíÍâдÁËÒ»¸öͬÑù¹¦ÄܵÄCÓïÑÔ³ÌÐò£¬Ö´ÐÐͬÑùµÄ²âÊÔÊý¾ÝµÃ³ö½á¹û½öÐèÒª10¡«15ÃëµÄʱ¼ä£¡shell ³ÌÐòȷʵҪ±ÈͬÑù¹¦ÄܵÄC³ÌÐòÂýһЩ£¬µ«ÊÇÄ¿Ç°µÄÇé¿öÊÇÓÃC³ÌÐò´¦ÀíÖ»ÐèÒª¼¸ÃëÖÓʱ¼ä, ¶øShell³ÌÐòÈ·ÐèÒªÊýСʱ£¡ÔÚÓôËShell³ÌÐò´¦ÀíµÄʱºòÎÒÓÃTopÃüÁî¿´ÁËһЩϵͳ×ÊÔ´µÄÏûºÄ·¢ÏÖCPU¡¢ÄÚ´æÒÔ¼°IOµÄÕ¼Óö¼¼«Ð¡£¬ËµÃ÷ϵͳ×ÊÔ´ºÜ³ä×㣬²»ÊÇϵͳµÄÎÊÌâÔì³ÉÁ˳ÌÐò´¦ÀíËÙ¶ÈÂý¡£ÎÊÌâ³öÔÚÄÄÁËÄØ£¿

    ÎÒÓÃÃüÃûps -ef ¹Û²ìϵͳ½ø³ÌµÄÔËÐÐÇé¿ö£¬·¢ÏÖÿ¹ý¼¸ÃëÖ־ͻáÓÐÒ»¸öexpr½ø³Ì²úÉú£¬Õâ¸ö½ø³ÌÔËÐк̵ܶÄʱ¼ä¾ÍÏûʧÁË(²»×Ðϸ¹Û²ì¿ÉÄܶ¼¿´²»µ½ÓÐexprÕâ¸ö½ø³Ì²úÉú)¡£ÕâʱºòÎÒ¾õµÃÎÒºÃÏñ·¢ÏÖ³ÌÐòÔËÐÐÂýµÄÔ­ÒòÁË£º³ÌÐòµÄ¼¸¸öÑ­»·ÀïÃ涼ÓÐÓÃexpr½øÐмÆËãµÄÓï¾ä£¬exprÊôÓÚShellÍⲿÃüÁËùÒÔÿ´ÎÔËË㶼Ҫ²úÉúÒ»¸ö expr½ø³Ì£¬¶ø³ÌÐòµÄÔËÐÐÖÖ×îÏûºÄʱ¼äµÄ³ýÁËIO²Ù×÷Íâ¾ÍÊý²úÉúнø³Ì²Ù×÷ÁË£¬ÓÚÊÇÎÒ¾ö¶¨°ÑÓÃexpr½øÐмÆËãµÄµØ·½¶¼¾¡Á¿ÐÞ¸ÄΪÓÃshellµÄÄÚ²¿ÃüÁî½øÐмÆËã¡£³ÌÐò±ä³ÉÁËÏÂÃæµÄÑù×Ó(±ê×¢1¡«±ê×¢6ΪÐ޸ĹýµÄµØ·½)£º

³ÌÐò´úÂëÈçÏ£º

¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D #!/bin/bash #Author Xsh date:08-15-2006 echo "Time:$(date)==>Strat to processing........." #ÏÔʾ³ÌÐò¿ªÊ¼ÔËÐÐʱ¼ä while read numseg do tmplow="${tmplow} $(expr substr ${numseg} 1 10 & >/dev/null ) " tmptop="${tmptop} $(expr substr ${numseg} 12 10 & >/dev/null ) " done < ./numseg.txt #Ñ­»·¶ÁÈ¡ºÅ¶ÎÎļþÏÂÏ޺ŶδæÈë±äÁ¿tmplow£¬ÉÏÏ޺ŶδæÈë±äÁ¿tmptop arr_lownug=(${tmplow}) #½«ÏÂÏ޺ŶδæÈëÊý×éarr_lownug arr_topnug=(${tmptop}) #½«ÉÏÏ޺ŶδæÈëÊý×éarr_topnug #¶¨Ò庯Êýchecknum()£¬ÊäÈë²ÎÊýΪÐèÒª¼ì²éµÄ"¼Æ·ÑºÅÂë"£¬Êä³ö²ÎÊýΪ0»òÕß1 #º¯Êýchecknum()Êä³öΪ0 ±íʾ"¼Æ·ÑºÅÂë" ²»ÔںŶÎÎļþµÄËùÓкŶη¶Î§ÄÚ #º¯Êýchecknum()Êä³öΪ1 ±íʾ"¼Æ·ÑºÅÂë" ÔںŶÎÎļþµÄËùÓкŶη¶Î§ÄÚ #º¯Êýchecknum()ÖÐÓöþ·ÖËÑË÷·¨½øÐкÅÂëµÄÅÐ¶Ï checknum(){ ££º¯Êý¶¨Ò忪ʼ thisnum=$1 ckresult=0 lowflag=0 topflag=$((${#arr_lownug[*]} - 1 )) #±ê×¢1 MaxIndex=$((${#arr_topnug[*]} - 1 )) #±ê×¢2 midflag=0 midflag=$((${topflag} / 2 )) #±ê×¢3 if [ "${thisnum}" \< "${arr_lownug[0]}" -o "${thisnum}" \> "${arr_topnug[${MaxIndex}]}" ] then return 0 else while [ "$lowflag" != "$midflag" ] do if ["$thisnum"\> "${arr_lownug[${midflag}]}" -o "$thisnum" == \ "${arr_lownug[${midflag}]}"] then lowflag=${midflag} midflag=$(( $((${topflag} + ${lowflag})) / 2 )) #±ê×¢4 elif["$thisnum"\<"${arr_lownug[${midflag}]}" -o "$thisnum" == \ "${arr_lownug[${midflag}]}"] then topflag=${midflag} midflag=$(($((${topflag} + ${lowflag})) / 2 )) #±ê×¢5 else echo "Error!" fi done if ["$thisnum" \< "${arr_topnug[${lowflag}]}" -o "$thisnum" == \ "${arr_topnug[${lowflag}]}"] then return 1 else return 0 fi fi }££º¯Êý¶¨Òå½áÊø while read f do org="${f:0:10}" #±ê×¢6 checknum ${org} returnval=$? if [ "$returnval" == "1" ] then echo "${f}" >> ./Match_result.cdr #½«Æ¥ÅäµÄ¼Ç¼´æÈë½á¹ûÎļþ1 else echo "${f}" >> ./NoMatch_result.cdr #½«²»Æ¥ÅäµÄ¼Ç¼´æÈë½á¹ûÎļþ2 fi done < ./rttest.txt echo "Time:$(date) ==> Proccess is end! " exit 0;

    ½«Ð޸ĹýµÄ³ÌÐò½øÐÐÔËÐУ¬ºÜ¿ì¾ÍµÃ³öÁ˽á¹û£¬×ܵÄÔËÐÐʱ¼äûÓг¬¹ý8·ÖÖÓ¡£´ËʱÕâ¸ö³ÌÐòµÄÔËÐÐЧÂÊÒѾ­»ù±¾¿ÉÒÔÈÃÈ˽ÓÊÜÁË¡£Í¬ÑùµÄÒ»¸öÎÊÌâÓÉÓڸĽøÁ˳ÌÐòËã·¨ºÍ³ä·ÖÀûÓÃÁËLinuxShellµÄÄÚÖÃÔËËã·û£¬½«³ÌÐòµÄÔËÐÐʱ¼ä´ó´óµÄËõ¶Ì¡£µ±È»´Ë³ÌÐò»¹ÓпÉÒԸĽøµÄµØ·½£¬¶Ô´ËÎĸÐÐËȤµÄ¶ÁÕß¿ÉÒԶԴ˳ÌÐò×ö½øÒ»²½ÓÅ»¯¡£

£¨³ö´¦£ºhttp://www.sheup.com£©