{"id":168309,"date":"2020-01-08T10:06:35","date_gmt":"2020-01-08T02:06:35","guid":{"rendered":"https:\/\/gulass.cn\/?p=168309"},"modified":"2019-12-30T11:09:04","modified_gmt":"2019-12-30T03:09:04","slug":"bash-shell-linux","status":"publish","type":"post","link":"https:\/\/gulass.cn\/bash-shell-linux.html","title":{"rendered":"\u5982\u4f55\u7528Bash \u811a\u672c\u5b9e\u73b0\u6bcf\u6b21\u767b\u5f55\u5230 Shell \u65f6\u53ef\u4ee5\u67e5\u770b Linux \u7cfb\u7edf\u4fe1\u606f"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\nLinux \u4e2d\u6709\u5f88\u591a\u53ef\u4ee5\u67e5\u770b\u7cfb\u7edf\u4fe1\u606f\u5982\u5904\u7406\u5668\u4fe1\u606f\u3001\u751f\u4ea7\u5546\u540d\u5b57\u3001\u5e8f\u5217\u53f7\u7b49\u7684\u547d\u4ee4\u3002\u4f60\u53ef\u80fd\u9700\u8981\u6267\u884c\u591a\u4e2a\u547d\u4ee4\u6765\u6536\u96c6\u8fd9\u4e9b\u4fe1\u606f\u3002\u540c\u65f6\uff0c\u8bb0\u4f4f\u6240\u6709\u7684\u547d\u4ee4\u548c\u4ed6\u4eec\u7684\u9009\u9879\u4e5f\u662f\u6709\u96be\u5ea6\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\u4f60\u53ef\u4ee5\u5199\u4e00\u4e2a shell \u811a\u672c \u57fa\u4e8e\u4f60\u7684\u9700\u6c42\u6765\u81ea\u5b9a\u4e49\u663e\u793a\u7684\u4fe1\u606f\u3002<\/p>\n

\u4ee5\u524d\u6211\u4eec\u51fa\u4e8e\u4e0d\u540c\u7684\u76ee\u7684\u9700\u8981\u5199\u5f88\u591a\u4e2a bash \u811a\u672c\u3002<\/p>\n

\u73b0\u5728\u6211\u4eec\u5199\u4e00\u4e2a\u65b0\u7684 shell \u811a\u672c\uff0c\u5728\u6bcf\u6b21\u767b\u5f55\u5230 shell \u65f6\u663e\u793a\u9700\u8981\u7684\u7cfb\u7edf\u4fe1\u606f\u3002<\/p>\n

\u8fd9\u4e2a\u811a\u672c\u6709 6 \u90e8\u5206\uff0c\u7ec6\u8282\u5982\u4e0b\uff1a<\/p>\n

    \u901a\u7528\u7cfb\u7edf\u4fe1\u606f\n<\/ol>\n
      CPU\/\u5185\u5b58\u5f53\u524d\u4f7f\u7528\u60c5\u51b5\n<\/ol>\n
        \u786c\u76d8\u4f7f\u7528\u7387\u8d85\u8fc7 80%\n<\/ol>\n
          \u5217\u51fa\u7cfb\u7edf WWN \u8be6\u60c5\n<\/ol>\n
            Oracle DB \u5b9e\u4f8b\n<\/ol>\n
              \u53ef\u66f4\u65b0\u7684\u5305
              \n\u6211\u4eec\u5df2\u7ecf\u57fa\u4e8e\u6211\u4eec\u7684\u9700\u6c42\u628a\u53ef\u80fd\u9700\u8981\u5230\u7684\u4fe1\u606f\u52a0\u5230\u4e86\u6bcf\u4e2a\u90e8\u5206\u3002\u4e4b\u540e\u4f60\u53ef\u4ee5\u57fa\u4e8e\u81ea\u5df1\u7684\u610f\u613f\u4fee\u6539\u8fd9\u4e2a\u811a\u672c\u3002<\/p>\n

              \u5982\u679c\u4f60\u60f3\u4e3a\u8fd9\u4e2a\u811a\u672c\u589e\u52a0\u5176\u4ed6\u7684\u4fe1\u606f\uff0c\u8bf7\u5728\u8bc4\u8bba\u53bb\u7559\u4e0b\u4f60\u7684\u9700\u6c42\uff0c\u4ee5\u4fbf\u6211\u4eec\u5e2e\u52a9\u4f60\u3002<\/p>\n

              Bash \u811a\u672c\u5b9e\u73b0\u6bcf\u6b21\u767b\u5f55\u5230 Shell \u65f6\u53ef\u4ee5\u67e5\u770b Linux \u7cfb\u7edf\u4fe1\u606f
              \n\u8fd9\u4e2a\u811a\u672c\u4f1a\u5728\u4f60\u6bcf\u6b21\u767b\u5f55 shell \u65f6\u628a\u7cfb\u7edf\u4fe1\u606f\u6253\u5370\u5230 terminal\u3002<\/p>\n

              # vi \/opt\/scripts\/system-info.sh\r\n#!\/bin\/bash\r\necho -e \"-------------------------------System Information----------------------------\"\r\necho -e \"Hostname:\\t\\t\"`hostname`\r\necho -e \"uptime:\\t\\t\\t\"`uptime | awk '{print $3,$4}' | sed 's\/,\/\/'`\r\necho -e \"Manufacturer:\\t\\t\"`cat \/sys\/class\/dmi\/id\/chassis_vendor`\r\necho -e \"Product Name:\\t\\t\"`cat \/sys\/class\/dmi\/id\/product_name`\r\necho -e \"Version:\\t\\t\"`cat \/sys\/class\/dmi\/id\/product_version`\r\necho -e \"Serial Number:\\t\\t\"`cat \/sys\/class\/dmi\/id\/product_serial`\r\necho -e \"Machine Type:\\t\\t\"`vserver=$(lscpu | grep Hypervisor | wc -l); if [ $vserver -gt 0 ]; then echo \"VM\"; else echo \"Physical\"; fi`\r\necho -e \"Operating System:\\t\"`hostnamectl | grep \"Operating System\" | cut -d ' ' -f5-`\r\necho -e \"Kernel:\\t\\t\\t\"`uname -r`\r\necho -e \"Architecture:\\t\\t\"`arch`\r\necho -e \"Processor Name:\\t\\t\"`awk -F':' '\/^model name\/ {print $2}' \/proc\/cpuinfo | uniq | sed -e 's\/^[ \\t]*\/\/'`\r\necho -e \"Active User:\\t\\t\"`w | cut -d ' ' -f1 | grep -v USER | xargs -n1`\r\necho -e \"System Main IP:\\t\\t\"`hostname -I`\r\necho \"\"\r\necho -e \"-------------------------------CPU\/Memory Usage------------------------------\"\r\necho -e \"Memory Usage:\\t\"`free | awk '\/Mem\/{printf(\"%.2f%\"), $3\/$2*100}'`\r\necho -e \"Swap Usage:\\t\"`free | awk '\/Swap\/{printf(\"%.2f%\"), $3\/$2*100}'`\r\necho -e \"CPU Usage:\\t\"`cat \/proc\/stat | awk '\/cpu\/{printf(\"%.2f%\\n\"), ($2+$4)*100\/($2+$4+$5)}' |  awk '{print $0}' | head -1`\r\necho \"\"\r\necho -e \"-------------------------------Disk Usage >80%-------------------------------\"\r\ndf -Ph | sed s\/%\/\/g | awk '{ if($5 > 80) print $0;}'\r\necho \"\"\r\necho -e \"-------------------------------For WWN Details-------------------------------\"\r\nvserver=$(lscpu | grep Hypervisor | wc -l)\r\nif [ $vserver -gt 0 ]\r\nthen\r\necho \"$(hostname) is a VM\"\r\nelse\r\ncat \/sys\/class\/fc_host\/host?\/port_name\r\nfi\r\necho \"\"\r\necho -e \"-------------------------------Oracle DB Instances---------------------------\"\r\nif id oracle >\/dev\/null 2>&1; then\r\n\/bin\/ps -ef|grep pmon\r\nthen\r\nelse\r\necho \"oracle user does not exist on $(hostname)\"\r\nfi\r\necho \"\"\r\nif (( $(cat \/etc\/*-release | grep -w \"Oracle|Red Hat|CentOS|Fedora\" | wc -l) > 0 ))\r\nthen\r\necho -e \"-------------------------------Package Updates-------------------------------\"\r\nyum updateinfo summary | grep 'Security|Bugfix|Enhancement'\r\necho -e \"-----------------------------------------------------------------------------\"\r\nelse\r\necho -e \"-------------------------------Package Updates-------------------------------\"\r\ncat \/var\/lib\/update-notifier\/updates-available\r\necho -e \"-----------------------------------------------------------------------------\"\r\nfi\r\n<\/pre>\n

              \u628a\u4e0a\u9762\u811a\u672c\u5185\u5bb9\u4fdd\u5b58\u5230\u4e00\u4e2a\u6587\u4ef6 system-info.sh\uff0c\u4e4b\u540e\u6dfb\u52a0\u53ef\u6267\u884c\u6743\u9650\uff1a<\/p>\n

              # chmod +x ~root\/system-info.sh\r\n<\/pre>\n

              \u5f53\u811a\u672c\u51c6\u5907\u597d\u540e\uff0c\u628a\u811a\u672c\u6587\u4ef6\u7684\u8def\u5f84\u52a0\u5230 .bash_profile \u6587\u4ef6\u672b\u5c3e\uff08\u7ea2\u5e3d\u7cfb\u5217\u7684\u7cfb\u7edf\uff1aCentOS\u3001Oracle Linux \u548c Fedora\uff09\uff1a<\/p>\n

              # echo \"\/root\/system-info.sh\" >> ~root\/.bash_profile\r\n<\/pre>\n

              \u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\uff0c\u6765\u8ba9\u4fee\u6539\u7684\u5185\u5bb9\u751f\u6548\uff1a<\/p>\n

              # source ~root\/.bash_profile\r\n<\/pre>\n

              \u5bf9\u4e8e Debian \u7cfb\u7edf\u7684\u7cfb\u7edf\uff0c\u4f60\u53ef\u80fd\u9700\u8981\u628a\u6587\u4ef6\u8def\u5f84\u52a0\u5230 .profile \u6587\u4ef6\u4e2d\uff1a<\/p>\n

              # echo \"\/root\/system-info.sh\" >> ~root\/.profile\r\n<\/pre>\n

              \u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u4f7f\u4fee\u6539\u751f\u6548\uff1a<\/p>\n

              # source ~root\/.profile\r\n<\/pre>\n

              \u4f60\u4ee5\u524d\u8fd0\u884c\u4e0a\u9762 source \u547d\u4ee4\u65f6\u53ef\u80fd\u89c1\u8fc7\u7c7b\u4f3c\u4e0b\u9762\u7684\u8f93\u51fa\u3002\u4ece\u4e0b\u6b21\u5f00\u59cb\uff0c\u4f60\u5728\u6bcf\u6b21\u767b\u5f55 shell \u65f6\u4f1a\u770b\u5230\u8fd9\u4e9b\u4fe1\u606f\u3002\u5f53\u7136\uff0c\u5982\u679c\u6709\u5fc5\u8981\u4f60\u4e5f\u53ef\u4ee5\u968f\u65f6\u624b\u52a8\u6267\u884c\u8fd9\u4e2a\u811a\u672c\u3002<\/p>\n

              \r\n-------------------------------System Information---------------------------\r\nHostname: daygeek-Y700\r\nuptime: 1:20 1\r\nManufacturer: LENOVO\r\nProduct Name: 80NV\r\nVersion: Lenovo ideapad Y700-15ISK\r\nSerial Number: AA0CMRN1\r\nMachine Type: Physical\r\nOperating System: Manjaro Linux\r\nKernel: 4.19.80-1-MANJARO\r\nArchitecture: x86_64\r\nProcessor Name: Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz\r\nActive User: daygeek renu thanu\r\nSystem Main IP: 192.168.1.6 192.168.122.1\r\n-------------------------------CPU\/Memory Usage------------------------------\r\nMemory Usage: 37.28%\r\nSwap Usage: 0.00%\r\nCPU Usage: 15.43%\r\n-------------------------------Disk Usage >80%-------------------------------\r\nFilesystem Size Used Avail Use Mounted on\r\n\/dev\/nvme0n1p1 217G 202G 4.6G 98 \/\r\n\/dev\/loop0 109M 109M 0 100 \/var\/lib\/snapd\/snap\/odrive-unofficial\/2\r\n\/dev\/loop1 91M 91M 0 100 \/var\/lib\/snapd\/snap\/core\/6405\r\n\/dev\/loop2 90M 90M 0 100 \/var\/lib\/snapd\/snap\/core\/7713\r\n-------------------------------For WWN Details-------------------------------\r\nCentOS8.2daygeek.com is a VM\r\n-------------------------------Oracle DB Instances---------------------------\r\noracle user does not exist on CentOS8.2daygeek.com\r\n-------------------------------Package Updates-------------------------------\r\n13 Security notice(s)\r\n9 Important Security notice(s)\r\n3 Moderate Security notice(s)\r\n1 Low Security notice(s)\r\n35 Bugfix notice(s)\r\n1 Enhancement notice(s)\r\n<\/pre>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"

              \u4f60\u53ef\u4ee5\u5199\u4e00\u4e2a shell \u811a\u672c \u57fa\u4e8e\u4f60\u7684\u9700\u6c42\u6765\u81ea\u5b9a\u4e49\u663e\u793a\u7684\u4fe1\u606f\u3002 \u4ee5\u524d\u6211\u4eec\u51fa\u4e8e\u4e0d\u540c\u7684\u76ee\u7684\u9700\u8981\u5199\u5f88\u591a\u4e2a bash […]<\/p>\n","protected":false},"author":1466,"featured_media":107149,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-168309","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/168309","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/users\/1466"}],"replies":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/comments?post=168309"}],"version-history":[{"count":10,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/168309\/revisions"}],"predecessor-version":[{"id":168617,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/168309\/revisions\/168617"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/media\/107149"}],"wp:attachment":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/media?parent=168309"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/categories?post=168309"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/tags?post=168309"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}