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
Compare date from db2 table to yesterday's Unix system date sasaliasim Shell Programming and Scripting 9 12-01-2008 11:37 PM
Perl: Extracting date from file name and comparing with current date MKNENI Shell Programming and Scripting 4 03-26-2008 04:01 PM
date issue-find prevoius date in a patricular format bsandeep_80 UNIX for Advanced & Expert Users 3 11-15-2007 08:42 PM
Changing Creation Date to a Prespecified Date of a File In Unix monkfan UNIX for Dummies Questions & Answers 4 11-28-2006 07:15 AM
Specify a previous date as start date in shell script ritzwan0 Shell Programming and Scripting 2 09-25-2006 06:58 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-20-2008
sfedak sfedak is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 7
Question date - 1 day

Hi, I have been trying just about every unix command to come up with yesterday's date (today's date - 1). I have seen all of the help on this forum, and none of it seems to work for me here. We are using Sun Solaris 9 Unix. I am using this script to create a .txt file with ftp commands that I will run from another script. All I want to do, is retrieve whatever files are at the ftp site with a date of yesterday in the filename. I have been trying to get the date right with Unix but obviously I am not having much luck.


I have tried a number of ways to get yesterday's date and none work for me.

#CalcDate=`date +%Y%m%d`
#CalcDate=`date -d yesterday +%Y%m%d`
#date="1 day ago" +"%Y%d%m"

I am able to output today's date to the .txt file using the following (see below).

CalcDate=`date +%Y%m%d`
cd /apps/PT8.44/outputs/backflow
echo 'lcd /apps/PT8.44/outputs/backflow/test' > bflowin.txt
echo 'mget *'$CalcDate* >> bflowin.txt
echo 'quit' >> bflowin.txt

Contents of bflowin.txt after script runs: I need it to be 20081119 (yesterday's date).

lcd /apps/PT8.44/outputs/backflow/test
mget *20081120*
quit

Any help you guys can give would be appreciated.
  #2 (permalink)  
Old 11-20-2008
Ikon's Avatar
Ikon Ikon is offline Forum Advisor  
Registered User
  
 

Join Date: Jul 2008
Location: Phoenix, Arizona
Posts: 669
This is how I had to get yesterdays day (HP-UX):

Code:
OFFSET=${1:-1}

case $OFFSET in
  *[!0-9]* | ???* | 3? | 29) print -u2 "Invalid input" ; exit 1;;
esac

eval `date "+day=%d; month=%m; year=%Y`
typeset -Z2 day month
typeset -Z4 year

day=$((day - OFFSET))
if (( day <= 0 )) ;then
  month=$((month - 1))
  if (( month == 0 )) ;then
    year=$((year - 1))
    month=12
  fi
  set -A days `cal $month $year`
  xday=${days[$(( ${#days[*]}-1 ))]}
  day=$((xday + day))
fi

echo $day

or try:


Code:
date '+%m %d %Y' |  
{  
read MONTH DAY YEAR 
DAY=`expr "$DAY" - 1`  
case "$DAY" in  
        0)  
           MONTH=`expr "$MONTH" - 1`  
                case "$MONTH" in  
                        0)  
                           MONTH=12  
                           YEAR=`expr "$YEAR" - 1`  
                        ;;  
                esac  
        DAY=`cal $MONTH $YEAR | grep . | fmt -1 | tail -1`  
esac  
echo "Yesterday was: $MONTH $DAY $YEAR"  
}

  #3 (permalink)  
Old 11-21-2008
sfedak sfedak is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 7
Thanks Ikon......the second code example worked perfectly for me. I am no longer frustrated! Have a great weekend :-)
Closed Thread

Bookmarks

Tags
unix commands

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:06 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0