Short Program for Checking Server date

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Short Program for Checking Server date
# 1  
Old 01-12-2012
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):

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



Last edited by vbe; 01-12-2012 at 05:43 AM.. Reason: corrected last code tag...
# 2  
Old 01-13-2012
Hi Guys,

Any feedback/suggestions so far? Any code would do. Smilie


# 3  
Old 01-13-2012
To list Invalid dates from infile ..
$ nawk '/Executing command in server/{print; getline; print}' infile | paste - - | grep -v "$(date +%a" "%b" "%d" "%T)"

# 4  
Old 01-13-2012
Hi jayan_jay,

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

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Program to combine two lines in a file on checking the first character of each line

Hi, I have a requirement where I need to combine two lines in a file based on first character of each line in a file. Please find the sample content of the file below: _______________________ 5, jaya, male, 4-5-90, single smart 6, prakash, male, 5-4-84, married fair 7, raghavi, female,... (12 Replies)
Discussion started by: jayaP
12 Replies

2. Programming

Help on digestion of C header files for a short program.

I found a very short but very efficient program to handle big sequence file (>30GB), but could not understand it. Wrote to the author but no reply, probably because the program needs comprehensive knowledge of C. Can any C expert "walk me thru" the two header files... (13 Replies)
Discussion started by: yifangt
13 Replies

3. UNIX for Dummies Questions & Answers

Short Mail Program Help

Hi, I have been out of the loop with my UNIX/Linux for several years and have been working mainframe. I was trying to create a short two line program to create a list of email addresses as a variable and then send the list a file. Here is what I did and I thought that is was right, but I am... (3 Replies)
Discussion started by: jbrider
3 Replies

4. Shell Programming and Scripting

Short program to select lines from a file based on a second file

Hello, I use UBUNTU 12.04. I want to write a short program using awk to select some lines in a file based on a second file. My first file has this format with about 400,000 lines and 47 fields: SNP1 1 12.1 SNP2 1 13.2 SNP3 1 45.2 SNP4 1 23.4 My second file has this format: SNP2 SNP3... (1 Reply)
Discussion started by: Homa
1 Replies

5. Shell Programming and Scripting

Valid date checking in the file

File contian below data... 20111101 20111102 20111131 I am new to unix and per scirpt... First two records are valid and last record is invalid,how to get the valid records... Please help me unix or perl script. :wall: Thanks, Murali (5 Replies)
Discussion started by: muralikri
5 Replies

6. Shell Programming and Scripting

awk columnwise adjacent match checking program

Hi, For the below problem, awk script is needed.. input file : jill jack jill jill jack jill jack jill Required: here, i need to check from first line. reference is jack. jill need to verified with next line jack. if found print jill & jack combination hill1 jack & jill &... (0 Replies)
Discussion started by: vasanth.vadalur
0 Replies

7. UNIX for Advanced & Expert Users

Checking mem usage at specific times in a program

Hi all, I'm running a simulator and I'm noticing an slow increase in memory for long simulations such that the simulation has to end because of a lack of memory. A colleague of mine ran Valgrind memcheck and reported that nothing of interest was reported other than known mem leaks. My advisor... (2 Replies)
Discussion started by: pl4u
2 Replies

8. Shell Programming and Scripting

Checking whether program is installed

I currently use this construction to check whether a certain program is installed: if ; then cd /usr/ports/databases/sqlite3 && make install clean else echo "sqlite already installed" fi Is this method recommended? Is this an effective method, ie sufficiently robust for... (3 Replies)
Discussion started by: figaro
3 Replies

9. Shell Programming and Scripting

Need help in checking the date and looking for a keyword in a script

Hi, I have a cron process that runs daily and generates a log file. The process writes the date it ran and also any errors to the log file. I need to write a script that will check if the process ran yesterday and also look for the keyword 'ERROR'. If it did not run yesterday or if it found... (0 Replies)
Discussion started by: tatchel
0 Replies

10. UNIX for Dummies Questions & Answers

KSH Checking Previous Date**

How would I go about getting the previous date on the server? I'm out of ideas...I am thinking that I could do it using the date command, but I am unable to find any information on doing it. For example if the current date is April 17th 2008 it would be (20080417) <- (YYYYMMDD). I need the previous... (4 Replies)
Discussion started by: developncode
4 Replies
Login or Register to Ask a Question

Featured Tech Videos