Linux monitoring: Difference between revisions
Jump to navigation
Jump to search
(Created page with "== Writting activity == === bash mylogs -ie "critical\|error\|\warn|\fail" === <pre> MyBin="mylogs" >~/$MyBin chmod 755 ~/$MyBin cat <<EOT >>~/$MyBin #!/bin/bash MyKey="\$@"...") |
No edit summary |
||
Line 1: | Line 1: | ||
== Writting activity == | == Writting activity == | ||
=== | === mylogs <filter> === | ||
<pre> | <pre> | ||
MyBin="mylogs" | MyBin="mylogs" | ||
Line 9: | Line 9: | ||
#!/bin/bash | #!/bin/bash | ||
MyKey="\$@" | if [ -z "\$@" ] ;then | ||
MyKey="-ie critical\\|error\\|warn\\|fail" | |||
else | |||
MyKey="\$@" | |||
fi | |||
MyBin="\$(basename \$0)" | MyBin="\$(basename \$0)" | ||
Line 20: | Line 24: | ||
NC='\033[0m' # No Color | NC='\033[0m' # No Color | ||
lsof -X 2>/dev/null |grep -E " [0-9]+w | lsof -X 2>/dev/null |grep " REG " |grep -E " [0-9]+w " |grep -o -P "(\/.+)" |sort -g |uniq |grep -v "/\${MyBin}.cfg\$" >~/\${MyBin}.cfg | ||
MyCacheFile="/tmp/\${MyBin}.\$\$" | MyCacheFile="/tmp/\${MyBin}.\$\$" | ||
Line 39: | Line 43: | ||
if [ "\$MyLogElapsed" -lt "\$MyTimeOut" ] ;then | if [ "\$MyLogElapsed" -lt "\$MyTimeOut" ] ;then | ||
MyResult="\$(tail -666 "\$MyLogPath" 2>/dev/null |strings |grep | MyResult="\$(tail -666 "\$MyLogPath" 2>/dev/null |strings |grep \$MyKey |tail -2 |cut -c1-111)" | ||
if [ -z "\$MyResult" ] ;then | if [ -z "\$MyResult" ] ;then | ||
MyResult="\$(tail -2 "\$MyLogPath" 2>/dev/null |strings |tail -2 |cut -c1-111)" | MyResult="\$(tail -2 "\$MyLogPath" 2>/dev/null |strings |tail -2 |cut -c1-111)" | ||
Line 70: | Line 74: | ||
</pre> | </pre> | ||
~/mylogs -ie "critical\|error\|\ | ~/mylogs -ie "critical\|error\|warn\|fail" |
Revision as of 23:08, 6 November 2016
Writting activity
mylogs <filter>
MyBin="mylogs" >~/$MyBin chmod 755 ~/$MyBin cat <<EOT >>~/$MyBin #!/bin/bash if [ -z "\$@" ] ;then MyKey="-ie critical\\|error\\|warn\\|fail" else MyKey="\$@" fi MyBin="\$(basename \$0)" MyTimeOutMin=900 MyTimeOutMax=3600 # bash colors RED='\033[0;31m' GREEN='\033[0;32m' NC='\033[0m' # No Color lsof -X 2>/dev/null |grep " REG " |grep -E " [0-9]+w " |grep -o -P "(\/.+)" |sort -g |uniq |grep -v "/\${MyBin}.cfg\$" >~/\${MyBin}.cfg MyCacheFile="/tmp/\${MyBin}.\$\$" function MyStep1 { >\${MyCacheFile} # 3 derniers jours du mois ou 9h à 17h en jour ouvré if [ \$(date +%d -d "3 day") -lt \$(date +%d) ] || { [ \$(date +%H) -ge 9 ] && [ \$(date +%H) -lt 17 ] && [ \$(date +%u) -lt 6 ] ;} ;then MyTimeOut=\$MyTimeOutMin else MyTimeOut=\$MyTimeOutMax fi cat ~/\${MyBin}.cfg |while read MyLogPath ;do if [ -f "\$MyLogPath" ] ;then MyLogElapsed=\$((\$(date +%s) - \$(date +%s -r "\$MyLogPath"))) if [ "\$MyLogElapsed" -lt "\$MyTimeOut" ] ;then MyResult="\$(tail -666 "\$MyLogPath" 2>/dev/null |strings |grep \$MyKey |tail -2 |cut -c1-111)" if [ -z "\$MyResult" ] ;then MyResult="\$(tail -2 "\$MyLogPath" 2>/dev/null |strings |tail -2 |cut -c1-111)" if [ ! -z "\$MyResult" ] ;then echo -e "\${NC}== \$MyLogPath ==" >>\${MyCacheFile} echo -e "\${GREEN}\${MyResult}\${NC}" >>\${MyCacheFile} fi else echo -e "\${NC}== \$MyLogPath ==" >>\${MyCacheFile} echo -e "\${RED}\${MyResult}\${NC}" >>\${MyCacheFile} fi fi fi done } MyStep1 cat \${MyCacheFile} |grep -v -w -f ~/\${MyBin}.cfg >~/\${MyBin}.ref while true ; do MyStep1 diff --changed-group-format='%>' --unchanged-group-format='' ~/\${MyBin}.ref \${MyCacheFile} >\${MyCacheFile}.diff clear cat \${MyCacheFile}.diff sleep 2 done EOT kill -9 $$
~/mylogs -ie "critical\|error\|warn\|fail"