Home » Infrastructure » Unix » File manipulation & sftp files (HP Unix)
File manipulation & sftp files [message #582381] Wed, 17 April 2013 15:37 Go to next message
Its_me_ved
Messages: 979
Registered: October 2009
Location: India
Senior Member
My requirement is explained below:

list of files available in server 1 in path /home/xxx/src are:
XX_SRC_20130417.txt
XX_SRC_20130417.dat
$cat XX_SRC_20130417.txt
col1=ABC
col2=
col3=xyz
a sequence file name is maintained which is in the path /ab_app/xx/seq
$cd /ab_app/xx/seq
$cat val.txt
xm|20130104|001|0
xy|20130704|002|1
xx|20130405|002|1
xz|20121213|001|1
Rule: Get the latest sequence value from the file for xx ie, 002.increment it by 1 (it will be 003) and store it in a variable.Make another copy of the file in /home/xxx/src renaming the file like below:

XX_SRC_20130417_003.txt
XX_SRC_20130417_003.dat
003 -> is the incremented number here.

Also, update the file XX_SRC_20130417_003.txt content with the incremented value

col1=ABC
col2=003
col3=xyz
sftp the newly created file.
If sftp is successful (used scp command to transfer files) for all the newly created two files sent( sent to server 2 , path: /extract/src/xx) then only update the content of val.txt with the incremented value.

After update, It should be something like:

xm|20130104|001|0
xy|20130704|002|1
xx|20130405|003|1             <---------------------------value updated here
xz|20121213|001|1
Remove the files below from /home/xxx/src(server1) no matter whether sftp is succeed or failed

XX_SRC_20130417_003.txt
XX_SRC_20130417_003.dat
Need your help and guidance to get the desired output.


I have made a draft of my approach something like below (its not the tested version as I have no unix box to test now):
source_dir=/home/xxx/src
seq_path=/ab_app/xx/seq
file_from_list=`ls  $source_dir/$file_name`
new_file_list=`ls  $source_dir/$new_file_name`
send_sftp(){
    scp $file_to_move $conn_string
    if [[ $? -eq 0 ]]
    then
        cnt=`expr $cnt+1`
        --when cnt=2 then update the val.txt file? 
    fi
    if [[ $? -ne 0 ]]
    then
        print "++++ File Transfer failed at `date +'%Y%m%d %H:%M%S'` " ;
        print "++++ File transfer failed at `date +'%Y%m%d %H:%M%S'`"
        exit 14
    fi
    rm $file_to_move ## irrespective of success or failure of sftp remove the new files
    if [[ $? -ne 0 ]]
    then
        print "++++ ERROR: File Transfer to  failed  at `date +'%Y%m%d %H:%M%S'` " ;
        print "++++    Transferred file could not be removed"
        exit 15
    fi
}
#if [[ $application_id = "2" ]]
#then
    print "Entering here..."
    conn_string=xxx@myserver2:/home/xxx/src
    file_name=xx_*
#fi
cd $seq_path
value=grep "xx" val.txt| cut -d"|" -f2
get_seq_val=$value+1
#if [[ $application_id = "2" ]]
#then
for list_files in $file_from_list
do
   fl_name=`basename list_files`
   fl=`echo $fl_name|cut -d'.' -f1`
   extn=`echo .${fl_name#*.}`
   new_file_name=$fl"_"$get_seq_val$extn  
   cp $list_files $new_file_name
done

for new_files in $new_file_list
do
   file_to_move=$new_files
   send_sftp()
   ### if all the files transferred successfully then update the value in value.txt file
   #-should we use sed to update the file? 
   #-can we track if all the files are sftp ed successfully? 
done
#fi


I need your help here.Please suggest if there is a better way in terms of approach/code to achieve this.

Thanks
Ved

[Updated on: Wed, 17 April 2013 15:56]

Report message to a moderator

Re: File manipulation & sftp files [message #582393 is a reply to message #582381] Thu, 18 April 2013 00:21 Go to previous message
Michel Cadot
Messages: 58938
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
This question bears no real connection with Oracle database.
Please find a more appropriate forum.
The topic is locked. ./fa/448/0/
If I'm wrong, please, PM me (or report this message to a moderator, explain why you think it should be unlocked and it might be done).

Regards
Michel
Previous Topic: Apache 2.2 on AIX 6.1 64 bit platform can't load a sample module
Next Topic: ORA-06575 During upgrade to Oracle 11g
Goto Forum:
  


Current Time: Sat Aug 30 11:29:41 CDT 2014

Total time taken to generate the page: 0.13679 seconds