Shell script for log analysis

Source: Internet
Author: User
 
 
  1. #! /Bin/sh
  2. # Show script description, different colors
  3. Echo-e"\ E[34; 1 m ###################################### ##########\ E[0 m"
  4. Echo-E"\ E[34; 1 m ### format like 'analysis _ log. Sh 2007-07-01 '###\ E[0 m"
  5. Echo-E"\ E[34; 1 m ### default parameters is today ###\ E[0 m"
  6. Echo-E"\ E[34; 1 m ###################################### ##########\ E[0 m"
  7. # Rsync Password
  8. Rsync_password =Ssoapi96
  9. ExportRsync_password
  10. # Obtain the number of parameters
  11. Var_parm_num =$ #
  12. # Defining temporary file names
  13. Tmp_log_file =/Tmp/API. Log
  14. Tmp_unique_file =/Tmp. Log
  15. # Check the parameter information and obtain a series of temporary log file names
  16. If[ $ Var_parm_num-EQ0 ];Then
  17. Today ='Date + % Y-% m-% d'
  18. Logfile =Api_log.$ Today
  19. Logfile96 =/Tmp/96_api_log.$ Today
  20. Logfile97 =/Tmp/97_api_log.$ Today
  21. Logfile98 =/Tmp/98_api_log.$ Today
  22. Logfile99 =/Tmp/99_api_log.$ Today
  23. Else
  24. Logfile =Api_log. $1
  25. Logfile96 =/Tmp/96_api_log. $1
  26. Logfile97 =/Tmp/97_api_log. $1
  27. Logfile98 =/Tmp/98_api_log. $1
  28. Logfile99 =/Tmp/99_api_log. $1
  29. Fi
  30. # Obtain log files (local, remote)
  31. CP/data/log/API/$ Logfile $ Logfile96
  32. Rsync-vzrtopg web @172.24. 139. 97: Apilog/$ Logfile $ Logfile97
  33. Rsync-vzrtopg web @172.24. 139. 98: Apilog/$ Logfile $ Logfile98
  34. Rsync-vzrtopg web @172.24. 139. 99: Apilog/$ Logfile $ Logfile99
  35. # Input the log files on different servers into one file and only go to3,4Column to remove rows containing keywords
  36. Cat$ Logfile96| Awk'{Print $3 ,"\ T"$4 }'| Grep-V"Sso_send">$ Tmp_log_file
  37. Cat$ Logfile97| Awk'{Print $3 ,"\ T"$4 }'| Grep-V"Sso_send">$ Tmp_log_file
  38. Cat$ Logfile98| Awk'{Print $3 ,"\ T"$4 }'| Grep-V"Sso_send">$ Tmp_log_file
  39. Cat$ Logfile99| Awk'{Print $3 ,"\ T"$4 }'| Grep-V"Sso_send">$ Tmp_log_file
  40. # Filter and sort all log files, remove duplicate records, and input them to another file.
  41. Sort-u$ Tmp_log_file>$ Tmp_unique_file
  42. # Output current time
  43. Echo-e"\ E[35; 1 m"'Date + % Y-% m-% d \ % H: % m: % s'"\ E[0 m"
  44. # Calculate the number of rows of certain actions, which is the number of actions
  45. Echo-e"\ E[36; 1 mlogin Nums\ E[0 m"
  46. Cat$ Tmp_log_file| Awk'{Print $1 }'| Grep"1"| WC-l
  47. Echo-E"\ E[32; 1 Muser Nums\ E[0 m"
  48. Cat$ Tmp_unique_file| Awk'{Print $1 }'| Grep"1"| WC-l
  49. Echo-E"\ E[33; 1mcheck_exist Nums\ E[0 m"
  50. Cat$ Tmp_log_file| Awk'{Print $1 }'| Grep"2"| WC-l
  51. # Deleting temporary log files
  52. Rm$ Tmp_log_file
  53. Rm$ Tmp_unique_file
  54. Rm$ Logfile96
  55. Rm$ Logfile97
  56. Rm$ Logfile98
  57. Rm$ Logfile99
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.