The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages 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 08: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 10:28 PM
how to delete record in file data with index in another file? zhynxn Shell Programming and Scripting 0 07-06-2006 12:03 AM
i want to delete a file based on existing file in a directory srivsn Shell Programming and Scripting 3 04-11-2006 04:38 AM
To delete a file at some other unix server dharmesht High Level Programming 1 03-23-2004 07:52 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rating: Thread Rating: 1 votes, 5.00 average. Display Modes
  #1 (permalink)  
Old 10-16-2005
lweegp lweegp is offline
Registered User
  
 

Join Date: Oct 2005
Location: singapore
Posts: 107
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
  #2 (permalink)  
Old 10-17-2005
blowtorch's Avatar
blowtorch blowtorch is offline Forum Advisor  
Supporter
  
 

Join Date: Dec 2004
Location: Singapore
Posts: 2,350
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
  #3 (permalink)  
Old 10-17-2005
lweegp lweegp is offline
Registered User
  
 

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

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

wee
  #4 (permalink)  
Old 10-17-2005
lweegp lweegp is offline
Registered User
  
 

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

it works!! thanks so much for the help.

wee
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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




All times are GMT -4. The time now is 11:24 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0