Comparing files named by date/time


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Comparing files named by date/time
# 1  
Old 05-30-2005
Data Comparing files named by date/time

I've looked at several of the previous posts and can't seem to find any that pertain to my problem, I'd appreciate some help if possible.

I have a directory with numerous logs of various names all named by heading and date ie.
dog.20050529.log
dog.20050530.log
pig.20050527.log
cat.20050521.log
etc.

What I'm trying to do is find the current date and see if there is a log for that date. After I find if the file is present I have a function to run (a simple tail). If a file for the current day is not there I want to have some instructions for people to follow to lead them to the proper log in another directory.

The logs change locations depending on the config and status of the system ie. system A is up the logs are on system A, if A is down the logs are on B.

Here is what I have for code very simple but...

#! /bin/ksh

##gets the file for the current date
set d1 = ls /log4/scripts/logs | grep dog.`date +%Y%m%d`.log

#compares the dates to ensure it is the current date
set d2 = `date +%Y%m%d`.log

if [[ $d1 = $d2 ]] then

tail -25 /log4/scripts/logs/dog.`date +%Y%m%d`.log

else

echo " instructions"

fi


my problem is that the tail works but I can't get any other function to run if a file of the current date is not available. I've tried the 'if' without the else, and with a separate 'if' with a new function but no luck. Thanks in advance.
Gil
# 2  
Old 05-30-2005
You have a few problem here. The set command doesn't set variables like that. If you want d1 to be set to "something" you do:
d1="something"
No spaces around the equal signs. If you want d1 set to the output of the date command, you could use the old syntax:
d1=`date`
or the new syntax:
d1=$(date)

The advantage of the new syntax is that nesting works and you need that advantage here:
d1=$(ls /log4/scripts/logs | grep dog.$(date +%Y%m%d).log)

But are you trying to see if a file exists?

if [[ -f /path/to/file ]] ; then
# 3  
Old 05-30-2005
Thanx for the answer, I've got to work with it for awhile to actually
understand what is going on and why (I'm a little slow and have to
see things a time or two for it to sink in).

Thanx again
gil
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Comparing files by date/time

I am trying to compare identically named files in different directories and replace a file only with a newer version. Is there a way of doing this? TIA (4 Replies)
Discussion started by: wbport
4 Replies

2. Shell Programming and Scripting

Files with date and time stamp

Hi Folks, Need a clarification on files with date and time stamp. Here is my requirement. There is a file created everyday with the following format "file.txt.YYYYMMDDHHMMSS". Now i need to check for this file and if it is available then i need to do some task to the file. I tried... (6 Replies)
Discussion started by: jayadanabalan
6 Replies

3. UNIX for Dummies Questions & Answers

Comparing two files with datestamp to current date

Hi, I am new to unix and I am stuck on how to compare two .zip file with date stamp in my directory. I need to compare out of the two file which is oldest to current date and unzip it after that done continue to unzip the second zip file. Thanks for your help. (5 Replies)
Discussion started by: lilvi3tboix1
5 Replies

4. Shell Programming and Scripting

How to catch date and time from log files?

Hi, Appli.log files contain the below data which updates continuously ================================================== =============== Tuple Created OrderEntry|66|39.0|ADML.L|16.89|GBP||GFD|000002889 41ORLO1|GB00B02J6398|80|XLON|UHORIZON|null|2011-05-09... (11 Replies)
Discussion started by: pspriyanka
11 Replies

5. Shell Programming and Scripting

compare date and time inside data of two files

i have two files with identical no of columns. 6th columns is date (MM/DD/YY format) and 7th columns is time (HH:MM:SS) format. I need to compare these two vaules and if the date & time is higher than fileA, save it on fileC; if the value is lower, then save it on fileD CONDITIONS... (7 Replies)
Discussion started by: ajiwww
7 Replies

6. Shell Programming and Scripting

pipe to file named with date

I would like to pipe (redirect ? - what is the right term?) the output of my script to a file named with the current date. If I run this at a command prompt: date +'%Y%m%d" ...it returns "20110429" OK, that's good... so I try: ./script.sh > "'date +%Y%m%d'.csv" I get a file... (1 Reply)
Discussion started by: landog
1 Replies

7. AIX

find files with specific date and time

Hi, I wanna to find files with specific date and time. I know this command: ls -ltr /system1/*.505 | grep 'Jan 18 09:00'. I want the 'Jan 18 09:00' not hard coded, I want it coming from the system date and time. And I want the time varies from 09:00-09:05. Is this possible without heavy... (3 Replies)
Discussion started by: itik
3 Replies

8. UNIX for Dummies Questions & Answers

List files with date and time stamps only

Hi there, I'm using terminal on mac and using the ls -l command to list all the files in a directory. However, I only want to display the date and time stamp of each file rather than permissions, owner, group etc... Is this possible? Many thanks in advance Dave (2 Replies)
Discussion started by: davewg
2 Replies

9. Shell Programming and Scripting

Copying files created after a specified date/time

I need to write a script that copies files from one directory to another that were created after "today 6:30". This script will be NOT be ran at the same time each day. any help is appreciated. (2 Replies)
Discussion started by: jm6601
2 Replies

10. UNIX for Dummies Questions & Answers

Renaming files to have date/time in filename

I have a program that will export my data to a single file, but it assigns a file name that is overridden every time I run the program. I need to change the file name to have a sequential number in the filename. How do I rename a file so that the filename contains the system date and time. I want... (5 Replies)
Discussion started by: wayneb
5 Replies
Login or Register to Ask a Question