Home » Infrastructure » Unix » FTP a file named yesterday's date
FTP a file named yesterday's date [message #97045] Tue, 30 October 2001 10:21 Go to next message
Shirley
Messages: 8
Registered: August 2000
Junior Member
In UNIX I want to FTP from another server. The filename will always be xxxxxxx.20011029 which will always be today's date minus one day. To capture today's date is:
dt=$(date +%Y%m%d)
How do I capture yesterday's date? And then will the value of that variable be recognized inside FTP???

----------------------------------------------------------------------
Re: FTP a file named yesterday's date [message #97046 is a reply to message #97045] Wed, 31 October 2001 15:19 Go to previous message
andrew again
Messages: 2577
Registered: March 2000
Senior Member
I don't know how to do the date arithmetic in shell scripting, but if you can connect to Oracle then you can do the calculation there and pass that back to the shell. Also, once you have that date, you can build an ftp command file using that value and then use that as an input to ftp.

Replace each '~' with a '<'
replace each '+' with a '>'

#!/bin/ksh
##export ORACLE_SID=my_db
##export ORACLE_HOME=/apps/oracle/app/oracle/product/8.0.4

## using anonomous pl/sql...
RETVAL=`sqlplus -s maceya/letmein ~~EOF
set serveroutput on
WHENEVER SQLERROR EXIT 1
declare
x varchar2(8);
begin
x := to_char(trunc(sysdate)-1, 'yyyymmdd');
dbms_output.put_line('yesterday_is '||x);
end;
/
exit;
EOF`

echo $RETVAL
X=`echo $RETVAL | awk '{print $2}'`
echo $X

## using an sql query....
sqlplus -s maceya/letmein ~~EOF | read RETVAL
set echo off heading off feedback off pagesize 0
WHENEVER SQLERROR EXIT 1
select to_char(trunc(sysdate)-1, 'yyyymmdd') from dual;
/
exit;
EOF

echo retval is $RETVAL

## building a command script to input into ftp later...
echo # here goes the first line... > ftp_script.txt
echo get xxxxx.$RETVAL ++ ftp_script.txt

----------------------------------------------------------------------
Previous Topic: Re: Problem Installation 8i on Linux
Next Topic: Re: Connect to a new Oracle errors
Goto Forum:
  


Current Time: Wed Apr 24 20:20:46 CDT 2024