{"id":171,"date":"2014-06-26T16:23:42","date_gmt":"2014-06-26T16:23:42","guid":{"rendered":"http:\/\/ixyzero.com\/blog\/?p=171"},"modified":"2014-06-26T16:23:42","modified_gmt":"2014-06-26T16:23:42","slug":"linux%e6%8a%80%e5%b7%a7%e5%ad%a6%e4%b9%a0ing","status":"publish","type":"post","link":"https:\/\/ixyzero.com\/blog\/archives\/171.html","title":{"rendered":"Linux\u6280\u5de7\u5b66\u4e60[ing]"},"content":{"rendered":"<h6>\u76d1\u89c6\u78c1\u76d8\u7a7a\u95f4\u4f7f\u7528\u91cf\u7684shell\u811a\u672c<\/h6>\n<pre class=\"lang:default decode:true\">#!\/bin\/bash\n#monitor disk space usage amount\nSPACE=`df | sed -n '\/\/$\/p' | awk '{print $5}' | sed 's\/%\/\/'`\nif [ $SPACE -ge 90 ]\nthen\n\techo \"Alert!!! Disk space has been used more than $SPACE%\" | mutt admin@ixyzero.com -s \"[disk space is not enough]\"\nfi<\/pre>\n<h6>\u4e3b\u673a\u72b6\u6001\u76d1\u63a7\u7684\u811a\u672c<\/h6>\n<pre class=\"lang:default decode:true \">#!\/bin\/bash\n# os_status_log.sh\n# 0 * * * * \/home\/useful_scripts\/os_status_log.sh\n\nDAT=\"`date +%Y%m%d`\"\nHOUR=\"`date +%H`\"\nDIR=\"\/home\/oslog\/host_${DAT}\/${HOUR}\"\nDELAY=60\nCOUNT=60\n\nif ! test -d ${DIR}\nthen\n\t\/bin\/mkdir -p ${DIR}\nfi\n\n# general check\n\/usr\/bin\/top -b -d ${DELAY} -n ${COUNT} &gt; ${DIR}\/top_${DAT}.log 2&gt;&amp;1 &amp;\n\n# cpu check\n\/usr\/bin\/sar -u ${DELAY} ${COUNT} &gt; ${DIR}\/cpu_${DAT}.log 2&gt;&amp;1 &amp;\n#\/usr\/bin\/mpstat -P 0 ${DELAY} ${COUNT} &gt; ${DIR}\/cpu_0_${DAT}.log 2&gt;&amp;1 &amp;\n#\/usr\/bin\/mpstat -P 1 ${DELAY} ${COUNT} &gt; ${DIR}\/cpu_1_${DAT}.log 2&gt;&amp;1 &amp;\n\n# memory check\n\/usr\/bin\/vmstat ${DELAY} ${COUNT} &gt; ${DIR}\/vmstat_${DAT}.log 2&gt;&amp;1 &amp;\n\n# I\/O check\n\/usr\/bin\/iostat ${DELAY} ${COUNT} &gt; ${DIR}\/iostat_${DAT}.log 2&gt;&amp;1 &amp;\n\n# network check\n\/usr\/bin\/sar -n DEV ${DELAY} ${COUNT} &gt; ${DIR}\/net_${DAT}.log 2&gt;&amp;1 &amp;\n#\/usr\/bin\/sar -n EDEV ${DELAY} ${COUNT} &gt; ${DIR}\/net_edev_${DAT}.log 2&gt;&amp;1 &amp;<\/pre>\n<p>&nbsp;<\/p>\n<h6>\u7528grep\u547d\u4ee4\u67e5\u627e\u542b\u6709&#8221;-&#8220;\u5b57\u7b26\u7684\u5185\u5bb9<\/h6>\n<p># <span style=\"color: #ff0000;\">history | grep -a<\/span><br \/>\nUsage: grep [OPTION]&#8230; PATTERN [FILE]&#8230;<br \/>\nTry `grep &#8211;help&#8217; for more information.<\/p>\n<p># <span style=\"color: #ff0000;\">history | grep &#8216;-a&#8217;<\/span><br \/>\nUsage: grep [OPTION]&#8230; PATTERN [FILE]&#8230;<br \/>\nTry `grep &#8211;help&#8217; for more information.<\/p>\n<p># <span style=\"color: #ff0000;\"><strong>history | grep &#8216;-a&#8217;<\/strong><\/span><br \/>\n2188 @2014-07-08_21:23:12 uname -a<br \/>\n2526 @2014-07-11_20:54:31 uname -a<br \/>\n2527 @2014-07-11_20:54:36 lsb_release -a<br \/>\n2697 @2014-07-13_18:30:52 ls -al<br \/>\n2698 @2014-07-13_18:31:01 ls -alh<br \/>\n2794 @2014-07-14_12:29:53 uname -a<\/p>\n<p>\u9700\u8981\u5c06\u8981\u67e5\u627e\u7684\u5185\u5bb9\u7528\u5f15\u53f7\u5f15\u8d77\u6765\uff0c\u7136\u540e\u4f7f\u7528\u53cd\u659c\u6760\u8f6c\u4e49\u7279\u6b8a\u5b57\u7b26\u3002<\/p>\n<h6>\u7528find\u547d\u4ee4\u67e5\u627e\u8fd1\u671f\u4fee\u6539\u8fc7\u7684\u6587\u4ef6<\/h6>\n<p># find \/root\/ -mtime -1 \u00a0#<span style=\"color: #ff0000;\">\u67e5\u627e\/root\u76ee\u5f55\u4e0b\u57281\u5929\u4e4b\u5185\u8fdb\u884c\u8fc7\u4fee\u6539\u7684\u6587\u4ef6\/\u6587\u4ef6\u5939<\/span><br \/>\n# find \/home\/ -mtime -1<\/p>\n<h6>\u67e5\u627e\u5927\u4e8e10MB\u7684\u6240\u6709\u6587\u4ef6<\/h6>\n<p>$ find \/ -size +10000k -xdev -exec ls \u2013lh {} ;<\/p>\n<h6>\u67e5\u770b\u5f53\u524d\u4f7f\u7528\u7684Shell\u7c7b\u578b<\/h6>\n<p>\u53ef\u4ee5\u4f7f\u7528echo $0\u6216ps -p $$\u547d\u4ee4\u663e\u793a\u60a8\u6b63\u5728\u4f7f\u7528\u7684Shell<\/p>\n<h6>\u91cd\u7528\u4ee5\u524d\u7684\u53c2\u6570\uff1a<\/h6>\n<p><span style=\"color: #ff0000;\"><strong>!$\u547d\u4ee4\u8fd4\u56de\u67d0\u4e2a\u547d\u4ee4\u4f7f\u7528\u7684\u4e0a\u4e00\u4e2a\u6587\u4ef6\u540d\u53c2\u6570<\/strong><\/span>\u3002\u4f46\u5982\u679c\u67d0\u4e2a\u547d\u4ee4\u4f7f\u7528\u591a\u4e2a\u6587\u4ef6\u540d\uff0c\u800c\u60a8\u53ea\u5e0c\u671b\u91cd\u7528\u5176\u4e2d\u4e00\u4e2a\u6587\u4ef6\u540d\uff0c\u8be5\u5982\u4f55\u505a\uff1f<strong><span style=\"color: #ff0000;\">!:1\u64cd\u4f5c\u7b26\u8fd4\u56de\u67d0\u4e2a\u547d\u4ee4\u4f7f\u7528\u7684\u7b2c\u4e00\u4e2a\u6587\u4ef6\u540d\uff0c!:2\u64cd\u4f5c\u7b26\u8fd4\u56de\u67d0\u4e2a\u547d\u4ee4\u4f7f\u7528\u7684\u7b2c\u4e8c\u4e2a\u6587\u4ef6\u540d<\/span><\/strong>\u3002\u5b9e\u9645\u6d4b\u8bd5\u5982\u4e0b\uff1a<\/p>\n<pre class=\"lang:default decode:true \"># ll ccrypt_useage.txt download_blogbus__latest.sh\n-rw-r--r-- 1 root root 2.4K Jun 22 01:41 ccrypt_useage.txt\n-rwxr--r-- 1 root root 843 Jun 25 22:22 download_blogbus__latest.sh*\n# ll !:1\nll ccrypt_useage.txt\n-rw-r--r-- 1 root root 2.4K Jun 22 01:41 ccrypt_useage.txt\n# ll ccrypt_useage.txt download_blogbus__latest.sh my.md5\n-rw-r--r-- 1 root root 2.4K Jun 22 01:41 ccrypt_useage.txt\n-rwxr--r-- 1 root root 843 Jun 25 22:22 download_blogbus__latest.sh*\n-rw-r--r-- 1 root root 306 Jul 20 16:53 my.md5\n# ll !:2\nll download_blogbus__latest.sh\n-rwxr--r-- 1 root root 843 Jun 25 22:22 download_blogbus__latest.sh*<\/pre>\n<p>&nbsp;<\/p>\n<h6>\u4f7f\u7528\u6587\u672c\u7f16\u8f91\u5668\u6253\u5f00\u4e0a\u4e00\u6b21\u6267\u884c\u7684\u547d\u4ee4<\/h6>\n<p>$ fc<br \/>\n\u5f53fc\u547d\u4ee4\u6267\u884c\u540e\uff0c\u4f1a\u7528\u6587\u672c\u7f16\u8f91\u5668\u6253\u5f00\u4e0a\u4e00\u4e2a\u547d\u4ee4\u3002\u5f53\u4f60\u60f3\u8981\u7f16\u8f91\u4e00\u4e2a\u5f88\u957f\u5e76\u4e14\u590d\u6742\u7684\u547d\u4ee4\u5f0f\uff0c\u8fd9\u4e2a\u529f\u80fd\u4f1a\u5e2e\u4f60\u7701\u4e0b\u4e0d\u5c11\u529f\u592b\u3002\uff08\uff08\u9ed8\u8ba4\u7684\u7f16\u8f91\u5668\u662fNano\uff0c\u5982\u679c\u4f60\u60f3\u8bbe\u7f6e\u7f16\u8f91\u5668\u4e3aVim\u4f60\u9700\u8981\u624b\u52a8\u6307\u5b9aEDITOR\u53d8\u91cf\u7684\u503c\uff09<br \/>\n<span style=\"color: #ff0000;\">\u6ce8\uff1a\u8bbe\u7f6e\u9ed8\u8ba4\u7684\u7f16\u8f91\u5668\u65b9\u6cd5\uff0c\u4f8b\u5982 vim\uff1aexport EDITOR=&#8217;vim&#8217;<\/span><\/p>\n<p>\u4f60\u53ef\u4ee5\u5c06\u5176\u5199\u5165~\/.bashrc\u4e2d\uff0c\u4ece\u800c\u4e0d\u7528\u6bcf\u6b21\u90fd\u624b\u52a8\u8bbe\u7f6e\uff09<\/p>\n<h4>Bash\u7ec8\u7aef\u5c0f\u6280\u5de7<\/h4>\n<h5>\u5220\u9664\u4e0a\u4e00\u4e2a\u5355\u8bcd<\/h5>\n<p>CTRL + w<br \/>\n\u5220\u9664\u4e00\u4e2a\u5355\u8bcd\u4e5f\u88ab\u79f0\u4e3a&#8221;killing a word&#8221;\uff0c\u6bcf\u4e2a\u88ab\u5220\u9664\u7684\u5355\u8bcd\u90fd\u88ab\u4fdd\u5b58\u5728\u7f13\u5b58\u4e2d\uff0c\u53ef\u4ee5\u6309\u4e0bCTRL + y\u5c06\u5176\u7c98\u8d34\u56de\u6765\uff0c\u8fd9\u4e2a\u64cd\u4f5c\u88ab\u79f0\u4e3a&#8221;yanking&#8221;\u3002<\/p>\n<h5><span style=\"color: #ff0000;\">\u6b63\u5411\u5386\u53f2\u641c\u7d22<\/span><\/h5>\n<p>CTRL + s<br \/>\n\u5982\u679c\u4f60\u6309\u4e0bCTRL + s\uff0c\u7ec8\u7aef\u4f1a\u505c\u6b62\u5c4f\u5e55\u5237\u65b0\uff0c\u56e0\u4e3a\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u4f60\u7684\u7ec8\u7aef\u5c06\u5b83\u89e3\u91ca\u6210\u505c\u6b62\u8f93\u51fa\u6d41\u7684\u4fe1\u53f7\u3002\u5f53\u6211\u662f\u65b0\u624b\u65f6\uff0c\u8fd9\u79cd\u60c5\u51b5\u5feb\u628a\u6211\u903c\u75af\u4e86\u3002\u6bcf\u6b21\u6211\u4e0d\u5c0f\u5fc3\u6309\u4e0bCTRL + s\u540e\uff0c\u5c4f\u5e55\u5c31\u51bb\u7ed3\u4e86\uff0c\u7136\u540e\u6211\u5c31\u4e0d\u77e5\u9053\u53d1\u751f\u4e86\u4ec0\u4e48\u3002\u4e4b\u540e\uff0c\u6211\u624d\u5b66\u4f1a\u7528CTRL + q\u952e\u6765\u6062\u590d\u7ec8\u7aef\uff08\u4f60\u53ef\u4ee5\u7528\u8fd9\u79cd\u65b9\u6cd5\u53bb\u9017\u4e00\u9017\u83dc\u9e1f`(*\u2229_\u2229*)\u2032\uff09<\/p>\n<p>\u6b63\u786e\u7684\u65b9\u5f0f\u5e94\u8be5\u662f\u901a\u8fc7stty\u547d\u4ee4\u6765\u66f4\u6539\u7ec8\u7aef\u5bf9\u4e8eCTRL + s\u6309\u4e0b\u540e\u91c7\u53d6\u7684\u884c\u4e3a\uff1a<br \/>\n$ stty stop &#8216;undef&#8217;<br \/>\n\u8fd9\u6837\u4f1a\u53d6\u6d88\u9ed8\u8ba4\u7684\u505c\u6b62\u4fe1\u53f7\u7684\u5feb\u6377\u952e\u7ed1\u5b9a\uff0c\u7136\u540e\u4f60\u53ef\u4ee5\u5f00\u59cb\u4f7f\u7528 Bash \u7684CTRL + s\u529f\u80fd\u3002<br \/>\nCTRL + s\u5728 Bash \u4e2d\u7684\u4f5c\u7528\u548cCTRL + r\u76f8\u53cd\uff0c\u662f\u6267\u884c\u6b63\u5411\u5386\u53f2\u641c\u7d22\u3002<\/p>\n<h5>\u8f93\u5165\u7279\u6b8a\u5b57\u7b26<\/h5>\n<p>CTRL + v<br \/>\n\u6309\u4e0bCTRL + v\u4e4b\u540e\uff0c\u4f1a\u53d6\u6d88\u4e0b\u4e00\u4e2a\u8f93\u5165\u5b57\u7b26\u7684\u7279\u6b8a\u542b\u4e49\uff0c\u4f8b\u5982CTRL + v\u540e\u6309\u4e0bTAB\u952e\uff0c\u53ef\u4ee5\u5728\u547d\u4ee4\u884c\u4e0b\u8f93\u5165\u4e00\u4e2a\u5236\u8868\u7b26\uff0c\u6216\u8005\u4e4b\u540e\u6309\u4e0bCTRL + m\u4f1a\u8f93\u5165\u4e00\u4e2a Windows \u4e0b\u7684\u56de\u8f66\u7b26\uff08\u6ce8: ^M\uff09\u3002<\/p>\n<p>ngxtop\u7684\u4f7f\u7528\u603b\u7ed3\uff1a<\/p>\n<ul>\n<li>ngxtop info<\/li>\n<li>ngxtop &#8211;no-follow<\/li>\n<li>ngxtop &#8211;no-follow top remote_addr<\/li>\n<li>ngxtop &#8211;no-follow -i &#8216;status==404&#8217; print request status remote_addr<\/li>\n<\/ul>\n<p>\u82e5\u4f60\u9700\u8981\u76f4\u63a5\u7528\u7ec8\u7aef\uff0c\u800c\u4e0d\u662f\u4f9d\u9760\u4efb\u4f55shell\u811a\u672c\u6765\u8fdb\u884c\u5b9e\u6570\u8ba1\u7b97\u3002\u4f60\u4f1a\u600e\u4e48\u505a\uff08\u6bd4\u5982\u5b9e\u65707.56+2.453\uff09\uff1f<br \/>\n\u7b54\u6848 : \u6211\u4eec\u9700\u8981\u7528\u5982\u4e0b\u6240\u8ff0\u7684\u7279\u6b8a\u65b9\u5f0f\u4f7f\u7528bc\u547d\u4ee4\uff08$ echo 7.56 + 2.453 | bc\uff09\u5c067.56+2.453\u4f5c\u4e3a\u8f93\u5165\u901a\u8fc7\u7ba1\u9053\u8fdb\u5165bc\u4e2d\u3002<\/p>\n<h6>\u4eceWooYun\u77e5\u8bc6\u5e93\u4e2d\u770b\u5230\u7684\u51e0\u4e2a\u7b80\u5355\/\u6709\u7528\u7684\u68c0\u6d4b\u65b9\u6cd5<\/h6>\n<pre class=\"lang:default decode:true \">find . -type f -name '*.php' -mtime -7  #\u67e5\u627e\u5f53\u524d\u76ee\u5f55\u4e0b\u57287\u5929\u4e4b\u5185\u8fdb\u884c\u8fc7\u4fee\u6539\u7684PHP\u6587\u4ef6\n\nfind . -type f -name '*.php' | xargs grep -l \"eval *(\" --color\t#(\u7a7a\u683c\u540e\u9762\u52a0\u4e0a\u4e2a*\u4ee3\u8868\u5339\u914d\u4efb\u610f\u4e2a\u7a7a\u683c)\nfind . -type f -name '*.php' | xargs grep -l \"base64_decode *(\" --color\nfind . -type f -name '*.php' | xargs grep -l \"gzinflate *(\" --color\nfind . -type f -name '*.php' | xargs grep -l \"eval *(str_rot13 *(base64_decode *(\" --color\n\nfind . -type f -name '*.php' | xargs egrep -i \"(mail|fsockopen|pfsockopen|stream_socket_client|exec|system|passthru|eval|base64_decode) *(\"\n\nfind . -type f -name '*.php' | xargs egrep -i \"preg_replace *((['|\"])(.).*2[a-z]*e[^1]*1 *,\" --color\n\ndiff -r wordpress-clean\/ wordpress-compromised\/ -x wp-content\n#\u4e0a\u9762\u7684\u4f8b\u5b50\u662f\u6bd4\u8f83wordpress-clean\/\u548cwordpress-comprised\/\u8fd9\u4e24\u4e2a\u76ee\u5f55\uff0c\u5e76\u4e14\u76ee\u5f55\u91cc\u9762\u7684wp-content\/\u5b50\u76ee\u5f55\u4e0d\u6bd4\u8f83\n\n#\u67e5\u770b\u5f53\u524d\u8fd9\u4e2a\u76ee\u5f55\u91cc\u9762\u662f\u5426\u6709\u53ef\u7591\u6587\u4ef6{\u67e5\u627e\u6743\u9650\u4e3a777\u7684\u76ee\u5f55\u662f\u5426\u5b58\u5728php\u6587\u4ef6}\nsearch_dir=$(pwd)\nwritable_dirs=$(find $search_dir -type d -perm 0777)\nfor dir in $writable_dirs\n    do\n        #echo $dir\n        find $dir -type f -name '*.php'\ndone\n\n#\u9ed1\u5ba2\u7ecf\u5e38\u5728jpg\u6587\u4ef6\u4e2d\u63d2\u5165php\u4ee3\u7801\uff0c\u56e0\u6b64\u5728\u67e5\u8be2\u8fd9\u4e9b\u76ee\u5f55\u7684\u65f6\u5019\u4e5f\u8981\u67e5\u8be2jpg\u6587\u4ef6\nfind wp-content\/uploads -type f -iname '*.jpg' | xargs grep -i php\n#\u6ce8\u610f\uff1a-iname \u8868\u793a\u6587\u4ef6\u540d\u4e0d\u533a\u5206\u5927\u5c0f\u5199\uff1bgrep -i \u4e5f\u8868\u793a\u67e5\u627e\u5185\u5bb9\u4e0d\u533a\u5206\u5927\u5c0f\u5199<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u76d1\u89c6\u78c1\u76d8\u7a7a\u95f4\u4f7f\u7528\u91cf\u7684shell\u811a\u672c #!\/bin\/bash #monitor disk space usage [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[46,72,19],"class_list":["post-171","post","type-post","status-publish","format-standard","hentry","category-linux","tag-skills","tag-terminal","tag-tips"],"views":3446,"_links":{"self":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/171","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/comments?post=171"}],"version-history":[{"count":0,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/171\/revisions"}],"wp:attachment":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/media?parent=171"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/categories?post=171"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/tags?post=171"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}