Advertisement
Guest User

Untitled

a guest
Nov 25th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. Help(){
  4. echo "Hello. This is script for show last N time in log"
  5. }
  6.  
  7.  
  8. Solution() {
  9. start_time=$(date -d "$time" "+%Y-%m-%d %H:%M:%S")
  10. stop_time=$(date -d "$time $offset second" "+%Y-%m-%d %H:%M:%S")
  11.  
  12. while read -r UserDate; do
  13.  
  14. var=$(echo "$UserDate" | awk -F'|' '{print $2}' | sed -r 's/^\s+//g')
  15. time=$(date -d "$var" "+%Y-%m-%d %H:%M:%S")
  16. if [[ $time < $stop_time ]] || [[ $time == $stop_time ]] && [[ $time > $start_time ]] || [[ $time == "$start_time" ]]; then
  17. echo "$UserDate"
  18. fi
  19.  
  20. if [[ $time > $stop_time ]]; then
  21. exit
  22. fi
  23.  
  24.  
  25. done <"$path"
  26.  
  27. }
  28.  
  29. if [ "$*" = "" ]; then
  30. echo "Please enter parametres"
  31. exit
  32. fi
  33.  
  34. if [ "$1" == "" ] || [ "$2" == "" ] || [ "$3" == "" ]; then
  35. echo "no one or more parametr. Watch help"
  36. Help
  37. exit
  38. fi
  39.  
  40.  
  41. if [[ $1 = "--help" || $1 = "-h" ]]; then
  42. Help
  43. exit
  44.  
  45. fi
  46.  
  47. if [ -f "$1" ]; then
  48. path=$1
  49. else
  50. echo File not found
  51. exit
  52. fi
  53.  
  54. time=$2
  55. offset=$3
  56. Solution
  57. exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement