If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Copying files from a remote m/c

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-31-05, 00:01
karthik_se karthik_se is offline
Registered User
 
Join Date: Jan 2005
Posts: 1
Copying files from a remote m/c

Hi

I am very new to this shell scripting.I have a requirment where i need do check a directory on a remote m/c and copy files that are newly generated.I need to check the timestamp of the file and find out whther the file is newly generated or not.

I would really appreciate any help on this regard..
Reply With Quote
  #2 (permalink)  
Old 02-02-05, 13:55
fla5do fla5do is offline
Registered User
 
Join Date: Oct 2003
Location: Germany
Posts: 138
Hi karthik_se
try this

REMOTE_SERV="server"
REMOTE_PATH="/u1/tmp"
LOCAL_PATH="/u1/dbforum"
LOG_FILE="ttt.log"
> $LOCAL_PATH/$LOG_FILE
ftp $REMOTE_SERV <<-! 2>&1 | tee -i -a $LOCAL_PATH/$LOG_FILE > /dev/null 2>&1
cd $REMOTE_PATH
lcd $LOCAL_PATH
dir
bye
!

# in your local-LOG_FILE you get the file informations from your
# remote-directory like this

#-rw-r--r-- 1 informix 40 Feb 2 18:52 sh6020
#-rw-r--r-- 1 root 1518 Jan 30 21:29 tps15744
#-rw-r--r-- 1 root 1518 Jan 31 21:14 tps723
#-rw-r--r-- 1 root 1518 Jan 23 23:25 tps858

# Now check the Log_FILE for timestamps from today
# like this

TODAY=`date '+%d.%m.%Y'`

COPY=`cat $LOCAL_PATH/$LOG_FILE | awk -v T=$TODAY ' BEGIN { FS=" "}
{
day=substr( T, 1, 2 )
month=substr( T, 4 ,2 )
year=substr( T, 7 ,4 )
if ( month == 1 )
{
month_1 = "Jan"
}
if ( month == 2 )
{
month_1 = "Feb"
}
# and so on until Dezember

if ( $7 != year )
{
if ( $5 == month_1 )
{
if ( $6 == day )
{
print $8
}
}
}
}'`

# all files will be copied with timestamp from today

for i in $COPY
do
ftp $REMOTE_SERV <<-! 2>&1 | tee -i -a $LOCAL_PATH/$LOG_FILE > /dev/null 2>&1
cd $REMOTE_PATH
lcd $LOCAL_PATH
get $i
bye
!
done
__________________
Greetings from germany
Peter F.

Last edited by fla5do; 02-02-05 at 14:19.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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