{"id":266,"date":"2010-06-22T16:19:20","date_gmt":"2010-06-22T13:19:20","guid":{"rendered":"http:\/\/skeletor.org.ua\/?p=266"},"modified":"2016-10-14T14:21:05","modified_gmt":"2016-10-14T11:21:05","slug":"%d0%bf%d0%be%d0%bb%d0%b5%d0%b7%d0%bd%d0%be%d1%81%d1%82%d0%b8-%d0%bf%d1%80%d0%b8-%d1%80%d0%b0%d0%b1%d0%be%d1%82%d0%b5-%d1%81-shell","status":"publish","type":"post","link":"https:\/\/skeletor.org.ua\/?p=266","title":{"rendered":"[shell] \u041f\u043e\u043b\u0435\u0437\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 shell"},"content":{"rendered":"<p><strong><span style=\"color: #ff0000;\">1)\u041f\u043e\u0441\u0442\u0440\u043e\u0447\u043d\u043e\u0435 \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043d\u0438\u0435.<\/span><\/strong><\/p>\n<p><code>#!\/bin\/sh<br \/>\nwhile read myline<br \/>\ndo<br \/>\necho $myline<br \/>\ndone &lt; inputfile<br \/>\n<\/code><br \/>\n<!--more--><\/p>\n<p><strong><span style=\"color: #ff0000;\">2)\u0418\u043d\u043a\u0440\u0435\u043c\u0435\u043d\u0442 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439.<\/span><\/strong><\/p>\n<p><code>count=`expr $count + 1`<\/code><\/p>\n<p><strong><span style=\"color: #ff0000;\">3) \u041f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0432\u044b\u0432\u043e\u0434\u0430:<\/span><\/strong><\/p>\n<p>\u0412\u043e\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432:<\/p>\n<p><code>#(exim -bv -v -d+all user@domain.ua 2&gt;&amp;1) &gt; \/tmp\/test<br \/>\n#exim -bv -v -d+all user@domain.ua &gt;\/tmp\/test2 2&gt;&amp;1<\/code><\/p>\n<p><strong><span style=\"color: #ff0000;\">4) \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c and, or \u0432 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0435 if<\/span><\/strong><\/p>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u00a0&#8220;<strong>$count_inet&#8221; &gt; 7<\/strong> \u0438 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u00a0<strong>&#8220;$count_gw&#8221; &gt; 7<\/strong>. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <strong>-a<\/strong>. \u0415\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0443\u0441\u043b\u043e\u0432\u0438\u0435 or \u0442\u043e\u0433\u0434\u0430 \u0441\u0442\u0430\u0432\u0438\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440<strong> -o<\/strong><\/p>\n<p><code>if [ \"$count_inet\" -gt 7 -a \u00a0\"$count_gw\" -gt 7 ]<br \/>\nthen<br \/>\necho \"Ping Ok\"<br \/>\nelse<br \/>\necho \"Ping down\"<br \/>\nfi<\/code><\/p>\n<p><strong><span style=\"color: #ff0000;\">5) \u0426\u0438\u043a\u043b while<\/span><\/strong><\/p>\n<p><code>#!\/bin\/sh<br \/>\ncount=\"0\"<br \/>\nwhile [ $count -lt \"55\" ]<br \/>\ndo<br \/>\ncount=`expr $count + 1`<br \/>\nroute add -host `nslookup fs${count}.ex.ua | grep Address: | grep -v '#53' | awk '{print $2}'` 1.1.1.1<br \/>\ndone<\/code><\/p>\n<p><strong><span style=\"color: #ff0000;\">6) \u041f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0432 blackhole<\/span><\/strong><\/p>\n<p><code>&gt; \/dev\/null 2&gt;&amp;1<\/code><\/p>\n<p>\u0415\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f\u00a0<strong>pipe<\/strong>, \u0438\u043b\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043a\u043e\u043c\u0430\u043d\u0434 \u0438 \u043d\u0443\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0432\u044b\u0432\u043e\u0434 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430, \u0442\u043e\u0433\u0434\u0430 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u043c \u043a\u0440\u0443\u0433\u043b\u044b\u0435 \u0441\u043a\u043e\u0431\u043a\u0438:<\/p>\n<p><strong><em>\u041f\u0440\u0438\u043c\u0435\u04401<\/em><\/strong><\/p>\n<p><code>(command1 | command2) &gt; \/dev\/null 2&gt;&amp;1<\/code><\/p>\n<p><strong><em>\u041f\u0440\u0438\u043c\u0435\u04402<\/em><\/strong><\/p>\n<p><code>(command1 ; command2 | command3) &gt; \/dev\/null 2&gt;&amp;1<\/code><\/p>\n<p><strong><span style=\"color: #ff0000;\">7) awk \u0438\u043b\u0438 cut?<\/span><\/strong><\/p>\n<p>\u0414\u043b\u044f &#8220;\u0432\u044b\u0440\u0435\u0437\u0430\u043d\u0438\u044f&#8221; \u043f\u043e\u043b\u0435\u0439 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u043a\u0430\u043a <strong>awk<\/strong>, \u0442\u0430\u043a \u0438 <strong>cut<\/strong>. \u0414\u043b\u044f \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0438\u0445 \u0444\u0430\u0439\u043b\u043e\u0432, \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u043d\u0435 \u0432\u0438\u0434\u043d\u0430, \u043d\u043e \u0434\u043b\u044f \u0444\u0430\u0439\u043b\u043e\u0432 \u0432 \u043f\u0430\u0440\u0443 \u0441\u043e\u0442 \u041c\u0411 \u0438\u043b\u0438 \u0434\u0430\u0436\u0435 \u0413\u0431, \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u043e\u0449\u0443\u0442\u0438\u043c\u0430 \u0432 \u043f\u043e\u043b\u044c\u0437\u0443 <strong>cut<\/strong>.<\/p>\n<p><strong><span style=\"color: #ff0000;\">8 ) \u041f\u043e\u0441\u0442\u0440\u043e\u0447\u043d\u043e\u0435 \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u043d\u0438\u0435 \u0438\u0437 \u0432\u044b\u0432\u043e\u0434\u0430 \u043a\u043e\u043c\u0430\u043d\u0434\u044b<\/span><\/strong><\/p>\n<p>\u041d\u0443\u0436\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0432\u044b\u0432\u043e\u0434 \u043a\u043e\u043c\u0430\u043d\u0434\u044b <strong>ps -efc | grep nginx<\/strong>, \u043f\u0440\u0438\u0447\u0451\u043c \u043f\u043e\u0441\u0442\u0440\u043e\u0447\u043d\u043e.<\/p>\n<pre>out=`ps -efc | grep nginx`\r\nwhile IFS= read -r myline\r\ndo\r\n  out_array=(`${ECHO} $myline | ${AWK} '{print $3,$4,$8}' | ${TR} -d \"M\"`)\r\n  virtual_memory=`expr $virtual_memory + ${out_array[0]}`\r\n  physical_memory=`expr $physical_memory + ${out_array[1]}`\r\n  cpu_time=`expr $cpu_time + ${out_array[2]}`\r\ndone &lt;&lt;&lt; \"$out\"\r\n<\/pre>\n<p>9) \u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u044b<\/p>\n<p><a href=\"https:\/\/habrahabr.ru\/company\/mailru\/blog\/311762\/\">\u041f\u043e\u0434\u0432\u043e\u0434\u043d\u044b\u0435 \u043a\u0430\u043c\u043d\u0438 Bash<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>1)\u041f\u043e\u0441\u0442\u0440\u043e\u0447\u043d\u043e\u0435 \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043d\u0438\u0435. #!\/bin\/sh while read myline do echo $myline done &lt; inputfile<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"class_list":["post-266","post","type-post","status-publish","format-standard","hentry","category-others"],"_links":{"self":[{"href":"https:\/\/skeletor.org.ua\/index.php?rest_route=\/wp\/v2\/posts\/266","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/skeletor.org.ua\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/skeletor.org.ua\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/skeletor.org.ua\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/skeletor.org.ua\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=266"}],"version-history":[{"count":12,"href":"https:\/\/skeletor.org.ua\/index.php?rest_route=\/wp\/v2\/posts\/266\/revisions"}],"predecessor-version":[{"id":5051,"href":"https:\/\/skeletor.org.ua\/index.php?rest_route=\/wp\/v2\/posts\/266\/revisions\/5051"}],"wp:attachment":[{"href":"https:\/\/skeletor.org.ua\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=266"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/skeletor.org.ua\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=266"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/skeletor.org.ua\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=266"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}