Short Program for Checking Server date

Hi Guys,

Good morning! I have a file which looks something like this:

Command was launched from partition 0.


------------------------------------------------
Executing command in server server3
Thu Jan 12 11:10:39 EET 2012


------------------------------------------------
Executing command in server backup-server
Thu Jan 12 11:10:39 EET 2012


------------------------------------------------
Executing command in server server2
Thu Jan 12 11:10:39 EET 2012


------------------------------------------------
Executing command in server server1
Thu Jan 12 11:10:42 EET 2012


------------------------------------------------
Executing command in server server0
Thu Jan 12 11:10:42 EET 2012

You see that the text highlighted in red are all the same which means that each server's time is correct and consistent.

Can anyone help me on how to create a program which will automatically check for each line (per server entry) corresponding to time and will prompt the user if one or more of the server's date is not parallel with the correct system time.

This is my script below (but I don't know how to included the if condition adn where to parse each line of file):

#!/usr/bin/sh

awk '
/Executing command in server/ {curr_server=$NF}
/Executing command in server/ { if ($5~/backup-server/) { host="HOST1" }
else if ($5~/server0/) { host="HOST2" }
else if ($5~/server1/) { host="HOST3" }
else if ($5~/server2/) { host="HOST4" }
else if ($5~/server3/) { host="HOST5" }}
/EET/ { if (???) { printf ("\033[41;37mERROR! Incorrect date in %s/%s, %s.\033[0m\n", curr_server, host, $0);got_err=1 }}
END {if (got_err!=1) {print "\033[42;30mDATE Status = OK\033[0m"}}' /tmp/DATE_Output.debug

Thanks!

br,
rymnd_12345

Hi Guys,

Any feedback/suggestions so far? Any code would do. :slight_smile:

Thanks!

br,
rymnd_12345

To list Invalid dates from infile ..

$ nawk '/Executing command in server/{print; getline; print}' infile | paste - - | grep -v "$(date +%a" "%b" "%d" "%T)"

Hi jayan_jay,

Thank you! It works well.. Appreciate your help.

Br,
rymnd_12345