Issues with comparing 2 files timestamps


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Issues with comparing 2 files timestamps
# 1  
Old 10-29-2012
Issues with comparing 2 files timestamps

Hi,

Im trying to write a script to first check a directory and if the filename has "ACK" in it do nothing and exit but if it has "ORD" in the filename then compare it with a dummy file created 2 minutes previous and see which one is newer

Im getting a few errors which im unsure how to rectofy any help would be much appreciated

Code:
     1  #!/bin/bash 
     2  #This is a script to alert by email if we havn't received any responces from Sangers in the last 2 minutes
     3
     4  SD= /export/home/tjmoore/sangersdummy.log
     5  SL= /export/home/tjmoore/sangerslog.log
     6  SL1= /export/home/tjmoore/sangerslog1.log
     7  ORD= cat /export/home/tjmoore/sangerslog3.log
     8  SAF= /export/home/tjmoore/sangersalert.log
     9
    10  touch /export/home/tjmoore/sangersdummy.log
    11  echo "We have not received any responses from Sangers within the last 2 minutes" > /export/home/tjmoore/sangersalert.log
    12
    13  ls -t /apps/sangerstest | head -1 > /export/home/tjmoore/sangerslog.log
    14  echo "/apps/sangerstest/" > /export/home/tjmoore/sangerslog1.log
    15  paste -d '\0' $SL1 $SL > /export/home/tjmoore/sangerslog3.log
    16
    17  if grep "ORD.xml" $SL
    18  then
    19  if ls -t $SD $ORD | head -1 | grep "ORD.xml"
    20  then
    21  /usr/local/bds/mailsend.s mailx "Sangers Responses Alert" <email addres> <email address> /export/home/tjmo
ore/sangersalert.log
    22  else
    23  exit;
    24  fi

Errors im receiving are:

Code:
bash-3.00# /export/home/tjmoore/sangers_alert_test2
/export/home/tjmoore/sangerslog.log: line 1: Test: command not found
/export/home/tjmoore/sangerslog1.log: line 1: /apps/sangerstest/: is a directory
/export/home/tjmoore/sangersalert.log: line 1: We: command not found
/export/home/tjmoore/sangers_alert_test2: line 25: syntax error: unexpected end of file

# 2  
Old 10-29-2012
Quote:
Originally Posted by 02JayJay02
Hi,

Im trying to write a script to first check a directory and if the filename has "ACK" in it do nothing and exit but if it has "ORD" in the filename then compare it with a dummy file created 2 minutes previous and see which one is newer

Im getting a few errors which im unsure how to rectofy any help would be much appreciated

Code:
     1  #!/bin/bash 
     2  #This is a script to alert by email if we havn't received any responces from Sangers in the last 2 minutes
     3
     4  SD= /export/home/tjmoore/sangersdummy.log
     5  SL= /export/home/tjmoore/sangerslog.log
     6  SL1= /export/home/tjmoore/sangerslog1.log
     7  ORD= cat /export/home/tjmoore/sangerslog3.log
     8  SAF= /export/home/tjmoore/sangersalert.log
     9
    10  touch /export/home/tjmoore/sangersdummy.log
    11  echo "We have not received any responses from Sangers within the last 2 minutes" > /export/home/tjmoore/sangersalert.log
    12
    13  ls -t /apps/sangerstest | head -1 > /export/home/tjmoore/sangerslog.log
    14  echo "/apps/sangerstest/" > /export/home/tjmoore/sangerslog1.log
    15  paste -d '\0' $SL1 $SL > /export/home/tjmoore/sangerslog3.log
    16
    17  if grep "ORD.xml" $SL
    18  then
    19  if ls -t $SD $ORD | head -1 | grep "ORD.xml"
    20  then
    21  /usr/local/bds/mailsend.s mailx "Sangers Responses Alert" <email addres> <email address> /export/home/tjmo
ore/sangersalert.log
    22  else
    23  exit;
    24  fi

Errors im receiving are:

Code:
bash-3.00# /export/home/tjmoore/sangers_alert_test2
/export/home/tjmoore/sangerslog.log: line 1: Test: command not found
/export/home/tjmoore/sangerslog1.log: line 1: /apps/sangerstest/: is a directory
/export/home/tjmoore/sangersalert.log: line 1: We: command not found
/export/home/tjmoore/sangers_alert_test2: line 25: syntax error: unexpected end of file

There are several issues here:
  1. You can't have spaces after the "=" in shell variable assignments on lines 2-8. The way you have written these lines, you are setting those environment variables to empty strings while you execute the commands in the files named on those lines (and the first three diagnostic messages you're seeing errors you're getting from the commands in those files. If that is what you intended to happen, then you need to debug those command files before trying to debug this one.
  2. I don't understand what you're trying to do with the "cat" on line 7, but I'm guessing that you should just remove the cat and the spaces on both sides of it.
  3. And, the final diagnostic message comes from having an if statement on lines 17 and 19, but only one fi statement (on line 24) to terminate both of them.
I'm not making any attempt to debug the rest of your script since I'm not sure what you're trying to do with the issues raised above.

Hope this helps,
Don
# 3  
Old 10-29-2012
From the first look, remove the spaces from both side of "=" and re-run the script

Code:
     4  SD= /export/home/tjmoore/sangersdummy.log
     5  SL= /export/home/tjmoore/sangerslog.log
     6  SL1= /export/home/tjmoore/sangerslog1.log
     7  ORD= cat /export/home/tjmoore/sangerslog3.log
     8  SAF= /export/home/tjmoore/sangersalert.log

# 4  
Old 10-29-2012
Although I can't follow your code, the error msgs look like you're executing your log files. There's certainly one fi missing in your code. Pls post the execution log (set -vx) and the contents of all files.
# 5  
Old 10-29-2012
Date conversion help from dd/mm/yyyy to dd/Mon/yyyy i.e. 28/10/2012 to 28/Oct/2012

Hi I have a problem with Date format in my code.

1st I am trying to convert today's date to yesterday's using

YESTERDAY3=`perl -e '@y=localtime(time()-86400); printf "%04d/%02d/%02d",$y[5]+1900,$y[4]+1,$y[3];$y[3];'`

And once it is done I am trying to using the yesterday date in a grep command to compare a logfile. But, the date format in logfile is 28/Oct/2012.

Could you please help me convert 28/10/2012 to 28/Oct/2012.

Thank You!
# 6  
Old 10-29-2012
@nitinnankam

Please open a new thread

Image
This User Gave Thanks to itkamaraj For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Comparing two files and list the difference with common first line content of both files

I have two file as given below which shows the ACL permissions of each file. I need to compare the source file with target file and list down the difference as specified below in required output. Can someone help me on this ? Source File ************* # file: /local/test_1 # owner: own #... (4 Replies)
Discussion started by: sarathy_a35
4 Replies

2. Programming

SQL issues comparing Long field to sysdate

I am having hard time with this sql: select partition_name, high_value FROM user_tab_partitions WHERE table_name = 'WNP_TPRESPONSE_INSTANCE' and to_char(high_value) <= to_char(sysdate - 15, 'yyyymm') ; I get an error: ORA-00932: inconsistent datatypes: expected CHAR got LONG... (1 Reply)
Discussion started by: mrn6430
1 Replies

3. Shell Programming and Scripting

Find matching timestamps in two files.

OK. if the first file is : 3184 2014-07-28 04:15 global.Remote-Access 10.111.8.25 81.245.6.25 tcp 3268 3035 2014-07-28 04:16 global.Remote-Access 10.111.8.12 81.245.6.25 tcp 3268If the second file is: 1 Jul 28 04:12 2014-07-28 id967254(BGC-TLW-Cert) Tunneling: User with IP... (8 Replies)
Discussion started by: fxsme
8 Replies

4. Shell Programming and Scripting

Comparing two timestamps

Hi all!!, I'm using Ksh and working on Linux. I want to compare two timestamps, timestamp1 and timestamp2. Until, timestamp1 is lesser than timestamp2, i want to do something, lets say print something. The code i have written is: a=`date +%H:%M:%S` b=`date +%H:%M:%S -d" 1... (1 Reply)
Discussion started by: Jayaraman
1 Replies

5. Shell Programming and Scripting

Sorting the files on their timestamps

Hi, The file names are like XXXX_20111101.gz for 01 November 2011, etc. There might be several files for 01 November 2011 and I can find them using find DIR -name *_20111101.gz -exec ls -lt {} \; But I want to sort the listing returned by the above command on the timestamps of the files... (6 Replies)
Discussion started by: sagarparadkar
6 Replies

6. Shell Programming and Scripting

Comparing the matches in two files using awk when both files have their own field separators

I've two files with data like below: file1.txt: AAA,Apples,123 BBB,Bananas,124 CCC,Carrot,125 file2.txt: Store1|AAA|123|11 Store2|BBB|124|23 Store3|CCC|125|57 Store4|DDD|126|38 So,the field separator in file1.txt is a comma and in file2.txt,it is | Now,the output should be... (2 Replies)
Discussion started by: asyed
2 Replies

7. Shell Programming and Scripting

Bash script to copy timestamps of multiple files

Hi, I have a bunch of media files in a directory that have been converted (from MTS to MOV format), so my directory contains something like this: clip1.mts clip1.mov clip2.mts clip2.mov The problem is that the .mov files that have been created have the timestamps of the conversion task,... (2 Replies)
Discussion started by: Krakus
2 Replies

8. Shell Programming and Scripting

Getting all the .gz files between Two Date/TimeStamps

Hi, I am trying to write a script to ftp and get all the files between two date/time stamps from a archive directory. I have sent an attatchment of my archive directory. With the script I intend to get files for ex: between request.log.2008-08-22-03-53-49.gz &... (3 Replies)
Discussion started by: openspark
3 Replies

9. Shell Programming and Scripting

Concatenate all the files in folder on timestamps

Hi Gurus, Experts, I am facing a problem to concatenate all the files based on timeStamps. The Problem is like this . The are many files in a folder Which are of the below types Ack_to_MDS_20070809141159.xml Ack_to_MDS_20070809141157.xml Ack_to_MDS_20070809141155.xml... (19 Replies)
Discussion started by: srikanthgr1
19 Replies

10. Shell Programming and Scripting

Sort files by Date-timestamps available in filename & pick the sortedfiles one by one

Hi, I am new to Unix shell scripting. Can you please help me with this immediate requirement to code.. The requirement is as given below. In a directory say Y, I have files like this. PP_100000_28062006_122731_746.dat PP_100000_28062006_122731_745.dat PP_100000_28062006_122734_745.dat... (4 Replies)
Discussion started by: Chindhu
4 Replies
Login or Register to Ask a Question