FTP and file timestamp question

FTP and file timestamp question

Post by Chuck » Sat, 25 Jan 2003 13:55:41



I have a file that will have the same name every day, but it will be
updated hourly on the ftp server, thus only the timestamp will be
different.  It must be retrieved 24 times a day.

I have written a ksh script that will check the timestamp and proceed
accordingly depending on the timestamp found.  However the way it is
currently written I log into the ftp server twice.  First time in, I
dir . logname and then grep this for the timestamp.  If it matches the
last timestamp used(stored in Oracle), I halt the script but if it
does not match then I open another ftp session to actually get the
file.

My question is can someone point me in the right direction to learn
how to do this with a single connection before I have to put it on the
production box?

How can something like the following be modified to work correctly?
If the !TESTVAR line spawns a new session, how can I issue a set of OS
commands in it's place and check the return code before issuing the
get command?

#!/bin/ksh
print "###  inside ftp script ###"
print "### ftp host is " $1 " ###"
print "### user is " $2 " ###"
print "### filename is " $4 " ###"

print
ftp -n -v $1 <<EOF
binary
user $2 $3
dir . dir.log
!TESTVAR=`grep $4 dir.log | awk '{print $6 " " $7 " " $8 }'`
get $4 $DEST_DIR/$4
EOF

 
 
 

FTP and file timestamp question

Post by Barry Margoli » Sun, 26 Jan 2003 01:27:37




>I have a file that will have the same name every day, but it will be
>updated hourly on the ftp server, thus only the timestamp will be
>different.  It must be retrieved 24 times a day.

>I have written a ksh script that will check the timestamp and proceed
>accordingly depending on the timestamp found.  However the way it is
>currently written I log into the ftp server twice.  First time in, I
>dir . logname and then grep this for the timestamp.  If it matches the
>last timestamp used(stored in Oracle), I halt the script but if it
>does not match then I open another ftp session to actually get the
>file.

>My question is can someone point me in the right direction to learn
>how to do this with a single connection before I have to put it on the
>production box?

You can write an Expect script that starts up ftp, reads the output of the
dir command, and then either sends a "get" or "quit" command.

--

Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

 
 
 

FTP and file timestamp question

Post by Ian Springe » Sun, 26 Jan 2003 03:12:17


Quote:> >I have a file that will have the same name every day, but it will be
> >updated hourly on the ftp server, thus only the timestamp will be
> >different.  It must be retrieved 24 times a day.

> >I have written a ksh script that will check the timestamp and proceed
> >accordingly depending on the timestamp found.  However the way it is
> >currently written I log into the ftp server twice.  First time in, I
> >dir . logname and then grep this for the timestamp.  If it matches the
> >last timestamp used(stored in Oracle), I halt the script but if it
> >does not match then I open another ftp session to actually get the
> >file.

> >My question is can someone point me in the right direction to learn
> >how to do this with a single connection before I have to put it on the
> >production box?

> You can write an Expect script that starts up ftp, reads the output of the
> dir command, and then either sends a "get" or "quit" command.

Or you could use a 2-way pipe in ksh, though this would certainly be more
difficult:

ftp ... |&
read -p ...
print -p ...
etc..

Only advantage is there would be no dependency on Expect.

 
 
 

FTP and file timestamp question

Post by Barry Margoli » Sun, 26 Jan 2003 04:51:47




>Or you could use a 2-way pipe in ksh, though this would certainly be more
>difficult:

>ftp ... |&
>read -p ...
>print -p ...
>etc..

>Only advantage is there would be no dependency on Expect.

But you might run into a problem with stdio buffering.

--

Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

 
 
 

1. dir timestamps vs dir/file timestamps

Working on Solaris 7
something i never noticed and now am confused:
i used to think that directory modification time=modification time of
newest file under directory.
Does dir modification time only change
when files are created or removed under that directory?
There's no way to do an ls -ltr and see which directory contains the
newest files?

example:

drwxr-xr-x   3 root     sys          512 Jul 29 03:10 cron

337 joeh [sunji]:/var>cd cron
338 joeh [sunji]:/var/cron>ls -ltr
total 1024
-rw-------   1 root     bin       481504 Jul 29 03:10 olog
-rw-------   1 root     root       30756 Aug  2 11:45 log

--

access to a news server; thanks!
Disclaimer: opinions expressed my own and not representative of my employers

2. wu-ftpd config issue

3. How to create files with a timestamp in the file name?

4. RH 7.0 and IP Masquerading

5. How to output file's timestamp when print file in UNIX?

6. Problems reading whole CD with SCSI-CDROMs

7. rename files to include each file's timestamp

8. Multicast Problem with linux

9. How to output file's timestamp when print file in UNIX?

10. Matrox Mystique ands X.

11. ftp timestamp

12. Preserve Timestamps on FTP

13. Ftp timestamps