943,787 Members | Top Members by Rank

Ad:
Nov 5th, 2007
0

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

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sonya2525 is offline Offline
19 posts
since Jul 2006
Nov 5th, 2007
0

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

change
Shell Scripting Syntax (Toggle Plain Text)
  1. mput "go*"
  2. bye
  3. rm go*
  4. End-of-session
  5. exit 0
to
Shell Scripting Syntax (Toggle Plain Text)
  1. mput "go*"
  2. bye
  3. End-of-session
  4. rm go*
  5. 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.
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006
Nov 6th, 2007
0

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

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sonya2525 is offline Offline
19 posts
since Jul 2006
Nov 7th, 2007
0

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

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sonya2525 is offline Offline
19 posts
since Jul 2006
Nov 7th, 2007
0

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

I just noticed something, you use

Shell Scripting Syntax (Toggle Plain Text)
  1. ftp -n $Server <<End-of-Session
  2. ......
  3. 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.
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006
Nov 7th, 2007
0

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

use rm -f if you want forced delete

something like rm -Rf / will just destroy everything
Moderator
Featured Poster
Reputation Points: 183
Solved Threads: 89
Posting Virtuoso
DimaYasny is offline Offline
1,772 posts
since Jan 2007
Nov 7th, 2007
0

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

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
Reputation Points: 102
Solved Threads: 47
Posting Whiz
eggi is offline Offline
399 posts
since Oct 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Shell Scripting Forum Timeline: editors and tutorials
Next Thread in Shell Scripting Forum Timeline: Replace





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC