{"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":"
\u5bfc\u8bfb<\/td>\n | Linux \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
\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 # 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 |