{"id":70371,"date":"2020-02-18T11:36:59","date_gmt":"2020-02-18T03:36:59","guid":{"rendered":"https:\/\/nemarov.com\/?p=70371"},"modified":"2020-02-18T12:39:41","modified_gmt":"2020-02-18T04:39:41","slug":"bash-%d1%81%d0%ba%d1%80%d0%b8%d0%bf%d1%82%d1%8b-%d1%83%d1%80%d0%be%d0%ba-2","status":"publish","type":"post","link":"https:\/\/nemarov.com\/?p=70371","title":{"rendered":"Bash-\u0441\u043a\u0440\u0438\u043f\u0442\u044b. \u0423\u0440\u043e\u043a 2"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-70373\" src=\"https:\/\/nemarov.com\/wp-content\/uploads\/2020\/02\/shebang.png\" alt=\"\" width=\"200\" height=\"100\" \/><br \/>\n\u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442!<br \/>\n<a href=\"https:\/\/nemarov.com\/?p=70356\">\u0422\u0443\u0442<\/a> \u043c\u044b \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u043e\u0431\u0430\u043b\u043e\u0432\u0430\u043b\u0438\u0441\u044c \u0441 \u043a\u043e\u043d\u0441\u043e\u043b\u044c\u044e \u0438 \u043a\u043e\u043c\u0430\u043d\u0434\u0430\u043c\u0438.<br \/>\n\u041f\u043e\u0435\u0445\u0430\u043b\u0438)<\/p>\n<p><strong>\u0417\u0430\u0434\u0430\u0447\u0430:<\/strong> \u0432\u0437\u044f\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0438\u0437 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0443\u0440\u043e\u043a\u0430 \u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u043a\u0440\u0438\u043f\u0442 \u0441 \u0443\u0441\u043b\u043e\u0432\u0438\u0435\u043c, \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c\u0438 \u0438 \u0432\u044b\u0432\u043e\u0434\u043e\u043c \u0432 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b \u0441 \u0434\u0430\u0442\u043e\u0439.<br \/>\n<strong>\u0420\u0435\u0448\u0435\u043d\u0438\u0435:<\/strong><br \/>\n<code><br \/>\n#!\/bin\/bash<br \/>\nfreemem=$(free -m | grep Mem | sed 's\/\\s\\+\/ \/g' | cut -d' ' -f4)<br \/>\ndatetime=$(date +\\%Y-\\%m-\\%d@\\%R)<br \/>\nif (( $freemem &lt; 100 ))<br \/>\nthen<br \/>\necho \"$datetime $freemem Mbytes free RAM memory &lt; 100 Mbytes\"<br \/>\nelse<br \/>\necho \"$datetime $freemem Mbytes free RAM memory\"<br \/>\nfi<\/code><br \/>\n<strong>\u041f\u043e\u044f\u0441\u043d\u0435\u043d\u0438\u0435:<\/strong><br \/>\n<em>1. \u0424\u0430\u0439\u043b<\/em><br \/>\n\u0411\u044b\u0441\u0442\u0440\u0435\u043d\u044c\u043a\u043e \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0444\u0430\u0439\u043b <code>free-mem.sh<\/code> (\u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 \u0432\u0435\u0441\u044c\u043c\u0430 \u0443\u0441\u043b\u043e\u0432\u043d\u043e\u0435) \u0438 \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u0435\u043c \u0430\u0442\u0440\u0438\u0431\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u043e\u0441\u0442\u0438.<br \/>\n<code>touch .\/free-mem.sh<\/code><br \/>\n<code>chmod +x .\/free-mem.sh<\/code><br \/>\n<!--more--><br \/>\n\u0414\u0430\u043b\u0435\u0435 \u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u0443\u0435\u043c \u043a\u043e\u043d\u0441\u043e\u043b\u044c\u043d\u044b\u043c\u0438 \u0440\u0435\u0434\u0430\u043a\u0442\u043e\u0440\u0430\u043c\u0438 <code>vi<\/code> \u0438\u043b\u0438 <code>nano<\/code>, \u043d\u043e \u044f \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u043d\u0435 \u043f\u0430\u0440\u0438\u0442\u044c\u0441\u044f \u0438 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f Midnight Commander (mc) &#8212; \u0444\u0430\u0439\u043b\u043e\u0432\u044b\u0439 \u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440 \u0441 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u043c \u0442\u0438\u043f\u0430 Norton Commander \u0434\u043b\u044f UNIX-\u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c. \u0416\u043c\u0435\u043c <code>shift+F4<\/code> \u0438 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \ud83d\ude42 \u041d\u043e \u0438\u0441\u0442\u0438\u043d\u043d\u044b\u0435 \u044e\u043d\u0438\u043a\u0441\u043e\u0438\u0434\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043a\u043e\u043d\u0441\u043e\u043b\u044c, \u0442\u043e\u043b\u044c\u043a\u043e \u0445\u0430\u0440\u0434\u043a\u043e\u0440 \ud83d\ude00<\/p>\n<p><em>2. Shebang (\u0448\u0435\u0431\u0430\u043d\u0433)<\/em><br \/>\n\u0428\u0435\u0431\u0430\u043d\u0433 &#8212; \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0438\u0437 \u0434\u0432\u0443\u0445 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 <code>\"#!\"<\/code> \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u0444\u0430\u0439\u043b\u0430 \u0441\u043a\u0440\u0438\u043f\u0442\u0430.<br \/>\n\u0421\u0442\u0440\u043e\u043a\u0430 \u0448\u0435\u0431\u0430\u043d\u0433\u0430 \u0438\u043c\u0435\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0444\u043e\u0440\u043c\u0430\u0442: <code>#!interpreter [optional-arg]<\/code><br \/>\ninterpreter &#8212; \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u044b\u0439 \u043f\u0443\u0442\u044c \u043a \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u043e\u043c\u0443 \u0444\u0430\u0439\u043b\u0443<br \/>\noptional\u2011arg &#8212; \u043d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442<br \/>\n<code>#!\/bin\/bash<\/code> \u2014 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0444\u0430\u0439\u043b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>bash<\/code> (<strong>B<\/strong>ourne-<strong>A<\/strong>gain <strong>SH<\/strong>ell)<\/p>\n<p><em>3. \u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435<\/em><br \/>\nBash-\u0441\u043a\u0440\u0438\u043f\u0442\u044b \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0438 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435. \u041f\u043e\u0434\u043e\u0431\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0445\u0440\u0430\u043d\u044f\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u043d\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u0441\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u044f.<br \/>\n<code>site=\"nemarov.com\"<\/code> &#8212; \u0437\u0430\u0434\u0430\u0435\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 <code>site<\/code> \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 &#171;nemarov.com&#187;<br \/>\n<code>echo $site<\/code> &#8212; \u043a\u043e\u043c\u0430\u043d\u0434\u0430 <code>echo<\/code> \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u0441\u0442\u0440\u043e\u043a\u0443 \u0442\u0435\u043a\u0441\u0442\u0430 \u0432 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b<\/p>\n<p>bash-\u0441\u043a\u0440\u0438\u043f\u0442<code><br \/>\n#!\/bin\/bash<br \/>\nsite=\"nemarov.com\"<br \/>\necho $site<\/code><br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-70374\" src=\"https:\/\/nemarov.com\/wp-content\/uploads\/2020\/02\/echo.png\" alt=\"\" width=\"317\" height=\"65\" \/><\/p>\n<p>\u041f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f <code>freemem<\/code> \u0432 \u043d\u0430\u0448\u0435\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0438<br \/>\n<code>freemem=$(free -m | grep Mem | sed 's\/\\s\\+\/ \/g' | cut -d' ' -f4)<\/code><br \/>\n\u0417\u043d\u0430\u043a\u043e\u043c\u0430\u044f \u0441\u0442\u0440\u043e\u0447\u043a\u0430 \u0438\u0437 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0443\u0440\u043e\u043a\u0430, \u043d\u043e \u043d\u0430\u043c \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u0430 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f <code>$()<\/code><br \/>\n<code>$()<\/code> &#8212; \u043f\u043e\u0434\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u043a\u043e\u043c\u0430\u043d\u0434, \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0438\u0437 \u0432\u044b\u0432\u043e\u0434\u0430 \u043a\u043e\u043c\u0430\u043d\u0434 \u0438 \u043d\u0430\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u0435\u0451 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c.<br \/>\n\u0422.\u0435. \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e <code>freemem<\/code> \u0437\u0430\u043d\u0435\u0441\u0451\u0442\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u043e\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438.<\/p>\n<p>\u041f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f <code>datetime<\/code> \u0432 \u043d\u0430\u0448\u0435\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0438<br \/>\n<code>datetime=$(date +\\%Y-\\%m-\\%d@\\%R)<\/code><br \/>\ndate &#8212; \u043a\u043e\u043c\u0430\u043d\u0434\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0430\u044f \u0441 \u0434\u0430\u0442\u043e\u0439 \u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0442\u044c \u0434\u0430\u0442\u0443 \u0432 \u0440\u0430\u0437\u043d\u043e\u043e\u0431\u0440\u0430\u0437\u043d\u043e\u043c \u0444\u043e\u0440\u043c\u0430\u0442\u0435, \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u0438 \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0448\u043b\u043e\u0435 \u0438 \u0431\u0443\u0434\u0443\u0449\u0435\u0435 \u0432\u0440\u0435\u043c\u044f.<br \/>\nbash-\u0441\u043a\u0440\u0438\u043f\u0442<code><br \/>\n#!\/bin\/bash<br \/>\ndatetime=$(date +\\%Y-\\%m-\\%d@\\%R)<br \/>\necho $datetime<\/code><br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-70375\" src=\"https:\/\/nemarov.com\/wp-content\/uploads\/2020\/02\/date.png\" alt=\"\" width=\"333\" height=\"68\" \/><\/p>\n<p><em>4. \u041a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f if-then-else<\/em><br \/>\nif-then-else &#8212; \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u043f\u043e\u0442\u043e\u043a\u043e\u043c \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u043c\u0430\u043d\u0434. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u043d\u0435\u043a\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043c\u0435\u043d\u044c\u0448\u0435 \u0441\u0442\u0430, \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043e\u0434\u043d\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435, \u0432 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 &#8212; \u0434\u0440\u0443\u0433\u043e\u0435.<br \/>\n<code><br \/>\nif (( $freemem &lt; 100 ))<br \/>\nthen<br \/>\necho \"$datetime $freemem Mbytes free RAM memory &lt; 100 Mbytes\"<br \/>\nelse<br \/>\necho \"$datetime $freemem Mbytes free RAM memory\"<br \/>\nfi<\/code><\/p>\n<p>\u0412\u044b\u0432\u043e\u0434 \u043f\u0440\u0438 <code>if-then<\/code><br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-70377\" src=\"https:\/\/nemarov.com\/wp-content\/uploads\/2020\/02\/if-else-500x51.png\" alt=\"\" width=\"500\" height=\"51\" srcset=\"https:\/\/nemarov.com\/wp-content\/uploads\/2020\/02\/if-else-500x51.png 500w, https:\/\/nemarov.com\/wp-content\/uploads\/2020\/02\/if-else.png 502w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/p>\n<p>\u0412\u044b\u0432\u043e\u0434 \u043f\u0440\u0438 <code>if-else<\/code><br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-70376\" src=\"https:\/\/nemarov.com\/wp-content\/uploads\/2020\/02\/if-then.png\" alt=\"\" width=\"434\" height=\"51\" \/><\/p>\n<p>\u041c\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043b\u0438 \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443 (:ok:)<br \/>\n\u041d\u0430 \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u0432\u0441\u0435 \u0438 \u0432\u0441\u0435\u043c \u0445\u043e\u0440\u043e\u0448\u0435\u0433\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442! \u0422\u0443\u0442 \u043c\u044b \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u043e\u0431\u0430\u043b\u043e\u0432\u0430\u043b\u0438\u0441\u044c \u0441 \u043a\u043e\u043d\u0441\u043e\u043b\u044c\u044e \u0438 \u043a\u043e\u043c\u0430\u043d\u0434\u0430\u043c\u0438. \u041f\u043e\u0435\u0445\u0430\u043b\u0438) \u0417\u0430\u0434\u0430\u0447\u0430: \u0432\u0437\u044f\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0438\u0437 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0443\u0440\u043e\u043a\u0430 \u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u043a\u0440\u0438\u043f\u0442 \u0441 \u0443\u0441\u043b\u043e\u0432\u0438\u0435\u043c, \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c\u0438 \u0438 \u0432\u044b\u0432\u043e\u0434\u043e\u043c \u0432 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b \u0441 \u0434\u0430\u0442\u043e\u0439. \u0420\u0435\u0448\u0435\u043d\u0438\u0435: #!\/bin\/bash freemem=$(free -m | grep Mem | sed &#8216;s\/\\s\\+\/ \/g&#8217; | cut -d&#8217; &#8216; -f4) datetime=$(date +\\%Y-\\%m-\\%d@\\%R) if (( $freemem &lt; 100 )) then echo &#171;$datetime $freemem Mbytes free RAM&#8230; <a href=\"https:\/\/nemarov.com\/?p=70371\">\u0427\u0438\u0442\u0430\u0442\u044c \u0434\u0430\u043b\u0435\u0435 &raquo;<\/a><\/p>\n","protected":false},"author":2135,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,20],"tags":[],"class_list":["post-70371","post","type-post","status-publish","format-standard","hentry","category-1","category-20"],"_links":{"self":[{"href":"https:\/\/nemarov.com\/index.php?rest_route=\/wp\/v2\/posts\/70371","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nemarov.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nemarov.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nemarov.com\/index.php?rest_route=\/wp\/v2\/users\/2135"}],"replies":[{"embeddable":true,"href":"https:\/\/nemarov.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=70371"}],"version-history":[{"count":0,"href":"https:\/\/nemarov.com\/index.php?rest_route=\/wp\/v2\/posts\/70371\/revisions"}],"wp:attachment":[{"href":"https:\/\/nemarov.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=70371"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nemarov.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=70371"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nemarov.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=70371"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}