If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Newbie in the deep end

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-18-03, 05:22
mccrack_2003 mccrack_2003 is offline
Registered User
 
Join Date: Sep 2003
Location: ZA
Posts: 24
Angry Newbie in the deep end

Being a newbie ( unix is sooo cool ) my knowledge is not all that great. So i seek help. I need too automate the backup of log files. The problem comes in that log too be backed up is the day before. I thought this would be easy.

__________________________________________________ _________
day=x
date +%d > date.log
for dy in $(seq -w 31)
do
if grep $dy date.log
then day=$(expr $dy - 1) ;
fi
done
#
#
month=x
date +%B > month.log
for mnth in January February March April May June July August September October November December
do
if grep $mnth month.log
then month=$mnth ;
fi
done
#
#
year=x
date +%Y > year.log
for yr in 2000 2001 2002 2003 2004 2005
do
if grep $yr year.log
then year=$yr ;
fi
done
__________________________________________________ _________

Ok, it looks messy but i at least thougt it did the job.
Here's the prob : -
Line 6) then day=$(expr $dy - 1) ;
When $dy=1 , 1 - 1 =0 . Last time i checked the calendar there was no 0 of the month .

In a nutshell i somehow need too calculate the current date less 1 day. Can this be done or do i have too turn too another scripting language.
HELP!!
Reply With Quote
  #2 (permalink)  
Old 09-18-03, 06:35
Damian Ibbotson Damian Ibbotson is offline
Padawan
 
Join Date: Jun 2002
Location: UK
Posts: 525
Have a look at the command 'find'. The mtime option can be used to list files that have been modified within a specified number of 24 hour periods.

e.g.

find . -mtime 1

find . -mtime +1 (inverts the above)

HTH
Reply With Quote
  #3 (permalink)  
Old 09-18-03, 06:59
mccrack_2003 mccrack_2003 is offline
Registered User
 
Join Date: Sep 2003
Location: ZA
Posts: 24
Wink

Thanx for the nfo Damian. Problem is that find is gonna pull all files updated within last 24 hours. I need too somehow get 01-03-2003 too 28-02-2003 . So there is going too have too be some form of intelligence in it.
Reply With Quote
  #4 (permalink)  
Old 09-18-03, 07:30
Damian Ibbotson Damian Ibbotson is offline
Padawan
 
Join Date: Jun 2002
Location: UK
Posts: 525
Quote:
Originally posted by mccrack_2003
Thanx for the nfo Damian. Problem is that find is gonna pull all files updated within last 24 hours. I need too somehow get 01-03-2003 too 28-02-2003 . So there is going too have too be some form of intelligence in it.
You could use find with the -newer flag

First create a file with a timestamp to use as the cutoff point...

touch -t 200309181230.00 timeCutOffFile

find timeCutOffFile -newer yourLogFile

The above would return "timeCutOffFile" if it is newer than yourLogFile, hence...

if ! test -z "$(find timeCutOffFile -newer yourLogFile)"
then
# if the result of the find is not empty, yourLogFile must be older
doStuffWithYourLogFile
fi

You can stick some more logic round that and you should have what you want.

HTH
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On