Advertisement

08.19.2008 at 05:27AM PDT, ID: 23659258 | Points: 500
[x]
Attachment Details

shell script for getting two days old file...

Asked by deepak_tyco in KornShell (ksh)

Hi,

I have a shell script to get the two days old file.
But the problem i am facing here is when the current day is first day of month its giving me date as 00 instead of 31th  or 30th .
the script ;--

#!/bin/sh
START_TIME=`date +"%x %r %Z"`
echo "-----------------------------------------------------"
echo "FTP Start Time : " $START_TIME

# Get Two day old date & delete two day old files
PAST=2
PASTFR=3
CURRENTFR=1

DATE=`date +%Y%m%d`
PAST_DATE=`expr $DATE - $PAST`
PAST_DATE_FR=`expr $DATE - $PASTFR`



PAST_TIS_FILE=$PAST_DATE-TIS.txt
PAST_TIS_FR_FILE=$PAST_DATE_FR-TIS_FR.txt

PAST_CPD_FILE=$PAST_DATE-CPD.txt
PAST_ADSERVER_FILE=$PAST_DATE-AdServer.txt

cd /users/cookiexx/cookie/data/
echo "Deleting : " $PAST_TIS_FILE $PAST_TIS_FR_FILE $PAST_CPD_FILE $PAST_ADSERVER_FILE

rm -rf $PAST_TIS_FILE
rm -rf $PAST_DATE-TIS_FR.txt
rm -rf $PAST_CPD_FILE
rm -rf $PAST_ADSERVER_FILE

# Getting todays file from VS server
HOST='vsp-sjc-007'
USER='cookiexx'
PASSWD=''

#smjoshi
DATE_FR=`expr $DATE - $CURRENTFR`


#commented by monraut for .new file changes
#FILE_FR=$DATE_FR-TIS_FR.txt
#FILE=$DATE-TIS.txt

FILE_FR=$DATE_FR-TIS_FR.new
FILE=$DATE-TIS.new


FILE2='TIS_thresholds.txt'
LDIR_PATH='/users/cookiexx/cookie/data/'
LDIR_CONF_PATH='/users/cookiexx/cookie/conf/'
/usr/local/bin/sftp $HOST <<END_SCRIPT
cd ../
cd F:/
cd VSExports
lcd $LDIR_PATH
get $FILE
#smjoshi
get $FILE_FR

lcd $LDIR_CONF_PATH
get $FILE2
exit
END_SCRIPT
# Remove any extra junk characters from the files
cd /users/cookiexx/cookie/data
#dos2unix $FILE $FILE
/usr/local/bin/perl -p -i -e 's/\r\n/\n/' $FILE


#smjoshi
/usr/local/bin/perl -p -i -e 's/\r\n/\n/' $FILE_FR

cd /users/cookiexx/cookie/conf
#dos2unix $FILE2 $FILE2
/usr/local/bin/perl -p -i -e 's/\r\n/\n/' $FILE2
END_TIME=`date +"%x %r %Z"`
echo "FTP End Time : " $END_TIME

# added monraut for .new file changes

FILE_FR_1=$DATE_FR-TIS_FR.txt
FILE_1=$DATE-TIS.txt

cd /users/cookiexx/cookie/data
mv $FILE_FR $FILE_FR_1
mv $FILE $FILE_1




Can any body help me out?

regards
Deepak

Start Free Trial
[+][-]08.19.2008 at 05:40AM PDT, ID: 22259183

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.04.2008 at 12:11AM PDT, ID: 22384806

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628