Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- Help(){
- echo "Hello. This is script for show last N time in log"
- }
- Solution() {
- start_time=$(date -d "$time" "+%Y-%m-%d %H:%M:%S")
- stop_time=$(date -d "$time $offset second" "+%Y-%m-%d %H:%M:%S")
- while read -r UserDate; do
- var=$(echo "$UserDate" | awk -F'|' '{print $2}' | sed -r 's/^\s+//g')
- time=$(date -d "$var" "+%Y-%m-%d %H:%M:%S")
- if [[ $time < $stop_time ]] || [[ $time == $stop_time ]] && [[ $time > $start_time ]] || [[ $time == "$start_time" ]]; then
- echo "$UserDate"
- fi
- if [[ $time > $stop_time ]]; then
- exit
- fi
- done <"$path"
- }
- if [ "$*" = "" ]; then
- echo "Please enter parametres"
- exit
- fi
- if [ "$1" == "" ] || [ "$2" == "" ] || [ "$3" == "" ]; then
- echo "no one or more parametr. Watch help"
- Help
- exit
- fi
- if [[ $1 = "--help" || $1 = "-h" ]]; then
- Help
- exit
- fi
- if [ -f "$1" ]; then
- path=$1
- else
- echo File not found
- exit
- fi
- time=$2
- offset=$3
- Solution
- exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement