The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Delete words in File 1 from File 2 Enobarbus37 Shell Programming and Scripting 14 02-15-2008 05:09 AM
Post Shell programming: Question about source a file and read data from the file ccwq Shell Programming and Scripting 3 08-04-2007 07:28 PM
how to delete record in file data with index in another file? zhynxn Shell Programming and Scripting 0 07-05-2006 09:03 PM
i want to delete a file based on existing file in a directory srivsn Shell Programming and Scripting 3 04-11-2006 01:38 AM
To delete a file at some other unix server dharmesht High Level Programming 1 03-23-2004 04:52 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 10-16-2005
Registered User
 

Join Date: Oct 2005
Location: singapore
Posts: 86
Question Get file from source server and delete the ftp file

Hi there Everyone,

I need some help/information/advise for the following questions:

I'm writing the following script:

#Beginning of the script

ftp -n <source server> > ${log_dir}/test_get.log << END
user <user_name>@<IP Address> <passwd>
verbose
bin
!echo "'List Files Before Getting A0 Data'"
ls
!echo "'Getting A0 Data'"
lcd /usr/mir7/dmail/data # Destination
mget A0*
bye
END

ftp -n <source server> > ${log_dir}/test_get.log << END
user <user_name>@<IP Address> <passwd>
!echo "'List All A0 Data"
dir A0*
bye
END

echo "List A0 Files in Destination" >> ${log_dir}/test_get.log
ls ltr A0* | grep "A0*" >> ${log_dir}/test_get.log

#The End

After getting the file from the source server I would like to delete the file from the source server but only the files which I have ftp to my server. Is there anyway to do it? I understand ftp do not understand "if...then...else" or "while" statements. How can I go about doing it? Any ideas/ advise/ help will be much appreciated.

Thanks.

wee
Reply With Quote
Forum Sponsor
  #2  
Old 10-16-2005
blowtorch's Avatar
Supporter
 
Join Date: Dec 2004
Location: Singapore
Posts: 2,328
This is what you want.
Code:
#!/usr/bin/ksh
ftp -ivn <<EOJ >> /tmp/some_log_file
open server_name
user username password
asc
dir A0* /tmp/A0.lst
quit
EOJ
## at this point, we have the list of A0* files with us

echo "open server_name" >> /tmp/batch.out
echo "user user_name pass_word" >> /tmp/batch.out

awk '{print $NF}' /tmp/A0.lst | while read file; do
echo "get $file" >> /tmp/batch.out   #we construct a ftp batchfile that will
echo "del $file" >> /tmp/batch.out   #delete a file after it transfers it to
done                                          #our end
echo "bye" >> /tmp/batch.out
rm /tmp/A0.lst
ftp -ivn < /tmp/batch.out >> /tmp/some_log_file
Reply With Quote
  #3  
Old 10-16-2005
Registered User
 

Join Date: Oct 2005
Location: singapore
Posts: 86
hi blowtorch,

let me use your script and try it out. i will reply u once it has been tested. thanks man.

wee
Reply With Quote
  #4  
Old 10-16-2005
Registered User
 

Join Date: Oct 2005
Location: singapore
Posts: 86
hi blowtorch,

it works!! thanks so much for the help.

wee
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 10:25 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0