The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Friendz.. plz help me on this date function. psn123 UNIX for Advanced & Expert Users 14 07-23-2008 01:09 PM
Function to find day of any given date. RRVARMA Shell Programming and Scripting 5 05-12-2008 12:19 AM
Date Function charandevu Shell Programming and Scripting 1 04-02-2008 06:12 AM
Date Function charandevu Shell Programming and Scripting 1 04-02-2008 04:44 AM
date function abey Shell Programming and Scripting 2 02-27-2006 01:28 AM

Closed Thread
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-16-2001
Registered User
 

Join Date: Sep 2001
Posts: 2
Stumble this Post!
Question Date function question

hi guys!
just want to ask if you could help me with the sript i'm working on. i need to automatically generate a summarized report everyday for all transactions the day before and ftp it to another machine. my only problem is that i need to name the file as the date yesterday. for example if i would generate a report today (09172001), the filename should be 09162001.txt, i've read the man for date but i haven't got a clue as to what to do.
please help.
thanks!

Last edited by crpalermo; 09-16-2001 at 11:23 PM.
Forum Sponsor
  #2 (permalink)  
Old 09-17-2001
Registered User
 

Join Date: Sep 2001
Location: Ahmedabad
Posts: 1
Stumble this Post!
Thumbs up

Dear friend

write a few lines in the shell as follows:

bye using date format command store today's date value in variable dt

hence if todays date is 09282001 in mmddyyyy format
dt='09282001'
now store value of dt to a file
echo $dt>file1
now cut value of today's date in variable v1
v1=`cut -c3-4 file1`
now find out value of previous date by using expr command
v2=`expr $v1 -1`
now prepare the full date by replacing 3rd and 4th chr of file1 by value of v1

Of course you will also have to add validations for last date of months and for february also
hope expr command will help you

Wish you all the best

yours friendly
VRJoshi
  #3 (permalink)  
Old 09-17-2001
flim flam flamma jamma
 

Join Date: May 2001
Location: Chicago IL, USA
Posts: 1,006
Stumble this Post!
just a thought. I dont see much use of processing data and labeling it the day befor. why not just run it from cron @ end of bussiness day or even at 11:55pm then u dont have to worry about adding and subtracting from the date.?

also if you look at the date man page at the bottom there are plenty of examples of getting the date in a format you would like.
  #4 (permalink)  
Old 09-17-2001
PxT's Avatar
PxT PxT is offline
Registered User
 

Join Date: Oct 2000
Location: Sacramento, CA
Posts: 909
Stumble this Post!
Quote:
Originally posted by Optimus_P
why not just run it from cron @ end of bussiness day or even at 11:55pm then u dont have to worry about adding and subtracting from the date.?
Then what if something happens at 11:56, that wont be reflected in the log file. One solution might be to do something like:

Code:
DATESTRING=`date +%m%d%Y`

sleep 120

# run report, redirect to $DATESTRING.txt
Run it at 11:59pm from crontab...
  #5 (permalink)  
Old 09-17-2001
flim flam flamma jamma
 

Join Date: May 2001
Location: Chicago IL, USA
Posts: 1,006
Stumble this Post!
ptx: i agree but that is why i said run it late.ie 11:56. most business should be done.

but w/ your example i completly agree and it is a great idea to get the date string first then sleep for 2 mins then finish.
  #6 (permalink)  
Old 09-17-2001
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,448
Stumble this Post!
Well, I'm bored this afternoon...so
Code:
#!/usr/bin/ksh

set -A months 0 31 28 31 30 31 30 31 31 30 31 30 31
typeset -Z2 month_y day_y

today=$(date +%m%d%Y)

month_t=${today%??????}
year_t=${today#????}
day_t=${today%????}
day_t=${day_t#??}

((year_t % 100)) && ((leap = !(year_t % 4))) || ((leap = !(year_t % 400)))
((leap)) && ((months[2] = months[2] + 1))

((year_y = year_t))
((month_y = month_t))
((day_y = day_t - 1))

if ((!day_y)) ; then
   ((month_y = month_y - 1))
   if ((!month_y)) ; then
      ((year_y = year_y-1))
      ((month_y = 12))
   fi
   ((day_y = months[month_y]))
fi

yesterday=${month_y}${day_y}${year_y}
echo yesterday = $yesterday
	
exit 0
I think I got this right...I only tested it lightly.
  #7 (permalink)  
Old 09-17-2001
Registered User
 

Join Date: Sep 2001
Posts: 2
Stumble this Post!
Thanks for all the help guys! I highly appreciate it
Google The UNIX and Linux Forums
Closed Thread

Tags
linux

Thread Tools
Display Modes




All times are GMT -7. The time now is 11:06 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0