Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
find /abc/companies/ -name 'ABC141*.csv' | while read fname
   sftp ABC141@servername <<EOF
   cd ../ABC141_01/
   put $fname
   mv $fname ./archive/$(basename $fname)-$(date +%Y%m%d-%T)

I have tried using scp command and it doesn't work. I am using passwordless login ssh keys.

share|improve this question

closed as not constructive by womble, Michael Hampton, Scott Pack, HopelessN00b, Wesley Dec 15 '12 at 0:45

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.If this question can be reworded to fit the rules in the help center, please edit the question.

"Doesn't work" isn't very informative. Please post error messages, log entries and specific ways it deviates from expectations. – Dennis Williamson Oct 5 '10 at 20:32
It is giving me syntax error on line 20 saying unexpected end of file. And I don't have 20 lines in script even. – yogsma Oct 5 '10 at 20:35
up vote 4 down vote accepted

If the indentation shown in your question is the same as that in your actual script file, then that is likely your problem. Your EOF needs to be at the beginning of the line or you can use <<-EOF and that will allow you to indent the closing EOF but only using tabs - not spaces.

share|improve this answer
Thank You, it worked. – yogsma Oct 5 '10 at 21:07

Is the ABC141 connecting with a public/private key? If not, then sftp is waiting for a password when you're trying to pass it commands. Simply install a public key into servername:~ABC141/.ssh/authorized_keys and the private key into ~/.ssh/id_dsa or ~/.ssh/id_rsa and then sftp should connect cleanly without waiting for a password to be entered.

share|improve this answer
Yes, I am using keys. When I just try to connect through normal terminal, it works. But my script is not getting executed. – yogsma Oct 5 '10 at 20:20

Not the answer you're looking for? Browse other questions tagged or ask your own question.