3 deleted 272 characters in body
source | link

I'm making a script using BASH that greps the timestamp from a file (~/logs/Server_Info.log). Specifically, I want to pull the hour digit from the timestamp and record it onto a variable.

This is the format I used for the timestamp:

date +"%b-%d-%Y-%I:%M:%S %p"

And I used this script to pull the data:

#!/bin/bash
LAST_HOUR="$(( $(date +%I) - 1 ))"
SEARCH_STRING=$(date +"%b-%d-%Y-${LAST_HOUR}:")

timeval=$(grep "${SEARCH_STRING}" ~/logs/Server_Info.log)
echo "$timeval"

exit 0

However, whenever I execute this script, I either get two answers:

Blank output

-or-

04

which was completely wrong, because my timestamp is

Mar-24-2017-05:07:00 PM 

I am rather new at BASH Scripting. (probably 2-3 months since I started, honestly.) I need help identifying where I messed up; be it setting up variables correctly such as LAST_HOUR or my date formatting is incompatible, etc...\

I would greatly appreciate any help! :)

I'm making a script using BASH that greps the timestamp from a file (~/logs/Server_Info.log). Specifically, I want to pull the hour digit from the timestamp and record it onto a variable.

This is the format I used for the timestamp:

date +"%b-%d-%Y-%I:%M:%S %p"

And I used this script to pull the data:

#!/bin/bash
LAST_HOUR="$(( $(date +%I) - 1 ))"
SEARCH_STRING=$(date +"%b-%d-%Y-${LAST_HOUR}:")

timeval=$(grep "${SEARCH_STRING}" ~/logs/Server_Info.log)
echo "$timeval"

exit 0

However, whenever I execute this script, I either get two answers:

Blank output

-or-

04

which was completely wrong, because my timestamp is

Mar-24-2017-05:07:00 PM 

I am rather new at BASH Scripting. (probably 2-3 months since I started, honestly.) I need help identifying where I messed up; be it setting up variables correctly such as LAST_HOUR or my date formatting is incompatible, etc...\

I would greatly appreciate any help! :)

I'm making a script using BASH that greps the timestamp from a file (~/logs/Server_Info.log). Specifically, I want to pull the hour digit from the timestamp and record it onto a variable.

This is the format I used for the timestamp:

date +"%b-%d-%Y-%I:%M:%S %p"

And I used this script to pull the data:

#!/bin/bash
LAST_HOUR="$(( $(date +%I) - 1 ))"
SEARCH_STRING=$(date +"%b-%d-%Y-${LAST_HOUR}:")

timeval=$(grep "${SEARCH_STRING}" ~/logs/Server_Info.log)
echo "$timeval"

exit 0

However, whenever I execute this script, I either get two answers:

Blank output

-or-

04

which was completely wrong, because my timestamp is

Mar-24-2017-05:07:00 PM 
2 Format code
source | link

I'm making a script using BASH that greps the timestamp from a file (~/logs/Server_Info.log). Specifically, I want to pull the hour digit from the timestamp and record it onto a variable.

This is the format I used for the timestamp:

date +"%b-%d-%Y-%I:%M:%S %p"


date +"%b-%d-%Y-%I:%M:%S %p"

And I used this script to pull the data:


#!/bin/bash

LAST_HOUR="$(( $(date +%I) - 1 ))"

SEARCH_STRING=$(date +"%b-%d-%Y-${LAST_HOUR}:")

timeval=$(grep "${SEARCH_STRING}" ~/logs/Server_Info.log)

echo "$timeval"

exit 0


#!/bin/bash
LAST_HOUR="$(( $(date +%I) - 1 ))"
SEARCH_STRING=$(date +"%b-%d-%Y-${LAST_HOUR}:")

timeval=$(grep "${SEARCH_STRING}" ~/logs/Server_Info.log)
echo "$timeval"

exit 0

However, whenever I execute this script, I either get two answers:

Blank output

-or-

04

which was completely wrong, because my timestamp is

    Mar-24-2017-05:07:00 PM 

I am rather new at BASH Scripting. (probably 2-3 months since I started, honestly.) I need help identifying where I messed up; be it setting up variables correctly such as LAST_HOUR or my date formatting is incompatible, etc...\

I would greatly appreciate any help! :)

I'm making a script using BASH that greps the timestamp from a file (~/logs/Server_Info.log). Specifically, I want to pull the hour digit from the timestamp and record it onto a variable.

This is the format I used for the timestamp:

date +"%b-%d-%Y-%I:%M:%S %p"


And I used this script to pull the data:


#!/bin/bash

LAST_HOUR="$(( $(date +%I) - 1 ))"

SEARCH_STRING=$(date +"%b-%d-%Y-${LAST_HOUR}:")

timeval=$(grep "${SEARCH_STRING}" ~/logs/Server_Info.log)

echo "$timeval"

exit 0


However, whenever I execute this script, I either get two answers:

Blank output

-or-

04

which was completely wrong, because my timestamp is

    Mar-24-2017-05:07:00 PM 

I am rather new at BASH Scripting. (probably 2-3 months since I started, honestly.) I need help identifying where I messed up; be it setting up variables correctly such as LAST_HOUR or my date formatting is incompatible, etc...\

I would greatly appreciate any help! :)

I'm making a script using BASH that greps the timestamp from a file (~/logs/Server_Info.log). Specifically, I want to pull the hour digit from the timestamp and record it onto a variable.

This is the format I used for the timestamp:

date +"%b-%d-%Y-%I:%M:%S %p"

And I used this script to pull the data:

#!/bin/bash
LAST_HOUR="$(( $(date +%I) - 1 ))"
SEARCH_STRING=$(date +"%b-%d-%Y-${LAST_HOUR}:")

timeval=$(grep "${SEARCH_STRING}" ~/logs/Server_Info.log)
echo "$timeval"

exit 0

However, whenever I execute this script, I either get two answers:

Blank output

-or-

04

which was completely wrong, because my timestamp is

Mar-24-2017-05:07:00 PM 

I am rather new at BASH Scripting. (probably 2-3 months since I started, honestly.) I need help identifying where I messed up; be it setting up variables correctly such as LAST_HOUR or my date formatting is incompatible, etc...\

I would greatly appreciate any help! :)

1
source | link

How to grep a file for a timestamp? I'm looking for the hour digits

I'm making a script using BASH that greps the timestamp from a file (~/logs/Server_Info.log). Specifically, I want to pull the hour digit from the timestamp and record it onto a variable.

This is the format I used for the timestamp:

date +"%b-%d-%Y-%I:%M:%S %p"


And I used this script to pull the data:


#!/bin/bash

LAST_HOUR="$(( $(date +%I) - 1 ))"

SEARCH_STRING=$(date +"%b-%d-%Y-${LAST_HOUR}:")

timeval=$(grep "${SEARCH_STRING}" ~/logs/Server_Info.log)

echo "$timeval"

exit 0


However, whenever I execute this script, I either get two answers:

Blank output

-or-

04

which was completely wrong, because my timestamp is

    Mar-24-2017-05:07:00 PM 

I am rather new at BASH Scripting. (probably 2-3 months since I started, honestly.) I need help identifying where I messed up; be it setting up variables correctly such as LAST_HOUR or my date formatting is incompatible, etc...\

I would greatly appreciate any help! :)