Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2005
    Posts
    1

    Unanswered: 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..

  2. #2
    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
    Last edited by fla5do; 02-02-05 at 15:19.
    Greetings from germany
    Peter F.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •