User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Shell Scripting section within the Software Development category of DaniWeb, a massive community of 456,451 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,587 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Shell Scripting advertiser: Programming Forums
Views: 1391 | Replies: 6
Reply
Join Date: Jul 2006
Posts: 17
Reputation: sonya2525 is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
sonya2525 sonya2525 is offline Offline
Newbie Poster

After my script does ftp, it can't delete the files - URGENT

  #1  
Nov 5th, 2007
Hi,

I have a script which uploads files successfully to another server via ftp. But after the files are uploaded, I want them to be deleted (removed), but it doesn't seem to work. I would appreciate if someone could help me out with this. How can I modify my script so that the uploaded files will be deleted after the ftp session?

Here's the script:

#!/bin/sh
cd /opt.../logs

Server="xx.xx.xx.xx"
Username="sonya"
Password="s2525"

DstDir="/files/son"

ftp -n $Server <<End-of-Session
user $Username $Password
binary
cd $DstDir
prompt
mput "go*"
bye
rm go*
End-of-session
exit 0



Thanks a lot,
Sonya
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Feb 2006
Posts: 1,509
Reputation: masijade is a glorious beacon of light masijade is a glorious beacon of light masijade is a glorious beacon of light masijade is a glorious beacon of light masijade is a glorious beacon of light 
Rep Power: 10
Solved Threads: 136
masijade's Avatar
masijade masijade is offline Offline
Posting Virtuoso

Re: After my script does ftp, it can't delete the files - URGENT

  #2  
Nov 5th, 2007
change
mput "go*"
bye
rm go*
End-of-session
exit 0
to
mput "go*"
bye
End-of-session
rm go*
exit 0

Because the rm go* is being fed to the ftp command (everything up to "End-of-session" is being fed to the ftp command), but the ftp session ended at "bye", and if it hadn't you would have removed the files on the remote machine (if anywhere). That's why you move that command down after the "End-of-session" line.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote  
Join Date: Jul 2006
Posts: 17
Reputation: sonya2525 is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
sonya2525 sonya2525 is offline Offline
Newbie Poster

Re: After my script does ftp, it can't delete the files - URGENT

  #3  
Nov 6th, 2007
Hi,
Thanks a lot. I did as you said, and I also put the complete path, so instead of rm go* I used rm /..../go* and it worked!

Thanks again.
Sonya
Reply With Quote  
Join Date: Jul 2006
Posts: 17
Reputation: sonya2525 is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
sonya2525 sonya2525 is offline Offline
Newbie Poster

Re: After my script does ftp, it can't delete the files - URGENT

  #4  
Nov 7th, 2007
Hi,

I made a mistake by including the rm before the ftp session just to check if my file can be deleted, so i thought your solution works. But when i tried your solution, i still wasn't able to delete the file. I included the path as well, still couldn't delete. Sorry for the mistake... but i really can't figure out why it won't be deleted..??


Thanks,

Sonya
Reply With Quote  
Join Date: Feb 2006
Posts: 1,509
Reputation: masijade is a glorious beacon of light masijade is a glorious beacon of light masijade is a glorious beacon of light masijade is a glorious beacon of light masijade is a glorious beacon of light 
Rep Power: 10
Solved Threads: 136
masijade's Avatar
masijade masijade is offline Offline
Posting Virtuoso

Re: After my script does ftp, it can't delete the files - URGENT

  #5  
Nov 7th, 2007
I just noticed something, you use

ftp -n $Server <<End-of-Session
......
End-of-session

Those two tags don't match. That "End-of-(S/s)ession tag needs to be written exactly the same in both places.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote  
Join Date: Jan 2007
Location: Israel
Posts: 1,636
Reputation: DimaYasny will become famous soon enough DimaYasny will become famous soon enough 
Rep Power: 6
Solved Threads: 72
Featured Poster
DimaYasny DimaYasny is offline Offline
Posting Virtuoso

Re: After my script does ftp, it can't delete the files - URGENT

  #6  
Nov 7th, 2007
use rm -f if you want forced delete

something like rm -Rf / will just destroy everything
Real stupidity always beats Artificial Intelligence. (Terry Pratchett)

BA BizMg, MCSE, DCSE, Linux+, Network+
Reply With Quote  
Join Date: Oct 2007
Posts: 306
Reputation: eggi is on a distinguished road 
Rep Power: 2
Solved Threads: 29
eggi eggi is offline Offline
Posting Whiz

Re: After my script does ftp, it can't delete the files - URGENT

  #7  
Nov 7th, 2007
Just a quick thought: If you use a path, also, it's best to make it absolute (/opt/whatever/go) rather than relative (../go) otherwise changes in your script could change where you try to delete the files from; assuming it's a constant.

, Mike
Linux and Unix Tips, Tricks and Individual Advice - The Linux and Unix Menagerie!
------------------------------------------------------------------------
Having trouble passing cert exams? Check out How To Pass Any Computer Certification Test!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Shell Scripting Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Shell Scripting Forum

All times are GMT -4. The time now is 2:00 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC