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
adding or subtracting days in the o/p of date St.Fartatric UNIX for Dummies Questions & Answers 1 05-19-2008 04:10 AM
Cron to run first day of month to calculate date 3 months ago new2ss Shell Programming and Scripting 1 05-16-2007 11:28 PM
Subtract 2 months from the date mahekr2000 UNIX for Advanced & Expert Users 5 07-23-2006 09:01 AM
Subtracting date / timestamps roadcyclist Shell Programming and Scripting 0 06-21-2006 11:51 AM
subtracting a days from current date rameshspal Shell Programming and Scripting 1 03-09-2006 09:18 PM

Closed Thread
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-05-2002
Registered User
 

Join Date: Aug 2002
Posts: 2
Subtracting Two months from date

Hello:

I am running a script that creates a database and renames the output file to append the current date in month-year format. However, I need to append the date with todays date minus two months. For example:

Aug2002 should read Jun2002.

Here is a copy of my current script:
Code:
---------------------------------------------------------------------------------
  #!/bin/sh


#Build cube
rsserver -c -m/global/site/vendor/cognos/Dealerops/models/historymodels/oduchistorydomclosmo.mdl -DLogFileName=/global/site/vendor/cognos/Dealerops/log/histcur.log -kODUCDB2U=cognos/songoc01

#Set Date Variable for appending date to file name (month-year format)
cogdate="`date +%h%Y`"
#Set Return Status variable
ret_stat=$?

#Check the return status of rsserver, if okay, do the necessary file transfers
# and update the cube on PPES and make mail subject "SUCCESS". 
# Otherwise, change mail subject to "FAILURE"
if test $ret_stat -eq 0 
then
subject="HistoryCubeBuild:SUCCESS"

cd /global/site/vendor/Dealerops/cubes
cp ODUCHISTDOMCUR.mdc /global/site/vendor/Dealerops/cubes/History/HISTCUR"$cogdate".mdc

else
subject="HistoryCubeBuild:FAILURE"
fi


MailToNames="XXXX.com" 
OutputFile=/global/site/vendor/Dealerops/log/histcur.log
cat $OutputFile | mailx -s $subject $MailToNames

exit $ret_stat
added code tags for readability --oombera

Last edited by oombera; 02-18-2004 at 09:12 AM.
Forum Sponsor
  #2 (permalink)  
Old 09-05-2002
auswipe's Avatar
Registered User
 

Join Date: Nov 2001
Location: Wide Awake Wylie, Texas
Posts: 536
Re: Subtracting Two months from date

Quote:
Originally posted by jwatson12
Hello:
I am running a script that creates a database and renames the output file to append the current date in month-year format. However, I need to append the date with todays date minus two months. For example:
Check with man for your version of date and see if it supports the -v switch.

Under FreeBSD, I was able to use

Code:
date -v -2m +%h%Y
Example:

Code:
FreeBSD:auswipe:/home/auswipe $ date
Thu Sep  5 13:37:22 CDT 2002
FreeBSD:auswipe:/home/auswipe $ date -v -2m
Fri Jul  5 13:37:28 CDT 2002
FreeBSD:auswipe:/home/auswipe $ date -v -2m +%h%Y
Jul2002
__________________
Not quite as cool as all the other Kids...
  #3 (permalink)  
Old 09-05-2002
LivinFree's Avatar
Goober Extraordinaire
 

Join Date: Jul 2001
Location: Portland, OR, USA
Posts: 1,584
If you're using GNU date you can do this:
Code:
[...]
date --date="2 months ago" +%m%Y
[...]
If you're not using GNU date and would like to, you can get it at gnu.org, in the "sh-utils" package.
  #4 (permalink)  
Old 09-13-2002
Registered User
 

Join Date: Aug 2002
Posts: 2
Tool is not available. I am working in a production environment and cannot add utilities.

What this script is doing is calling an OLAP database kernel that generates financial numbers for a financial closing of two months prior to the system date. The filename must be in sync with the record dates in the database source.

Therefore, If System Month = Jan, then New Month = Nov, etc. Perhaps it is best to converrt the month to number. Any ideas or scripts someone can share?

Thanks,
Newbie
Google UNIX.COM
Closed Thread

Thread Tools
Display Modes




All times are GMT -7. The time now is 01:12 PM.


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