Advertisement
Guest User

Untitled

a guest
May 24th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. # The line below tells the system to use /bin/bash as the interpreter aka the program that executes the code
  2. #!/bin/bash
  3.  
  4. # The line below is variable called TODAYS_DATE that was assigned the output of the command to the right of the '='
  5. # Today, that variable would be 20180524. Tomorrow it would be 20180524. date is a system command that gets the current date info
  6. # If you see backquotes '`', it means whatever is inside the backquotes will be executed as system commands
  7.  
  8. TODAYS_DATE=`date +%Y%m%d`
  9.  
  10. # For loop structure. It might be easier to read right to left. The word 'file' is a variable in the for loop structure that will contain a file everytime the loop loops
  11. # This is saying, find every file in the path /var/log, and for every file, see if the file(ie filename) contains todays date.
  12. # If the filename contains todays date, print the filename with the echo command. echo just prints to the screen
  13. # cat prints the contents of a file to the terminal. But i am using the '|' symbol which takes the output from the previous command
  14. # so that it can continue manipulating the output. grep is a command that will search a file, and tail will output the last lines.
  15. # That line is printing out all the lines of the file, will search for all lines that contain the word 'kernel' and return only those lines, and then print out the last 10 lines that was left
  16. # and the file status (the stat command) prints the modified,access, and some other info to the shell/terminal
  17.  
  18. for file in `find /var/log`
  19. do
  20. if [[ $file =~ $TODAYS_DATE ]]
  21. then
  22. echo $file
  23. cat $file | grep kernel | tail -n 10
  24. stat $file
  25. fi
  26. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement