Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.
find /abc/companies/ -name 'ABC141*.csv' | while read fname
do
   sftp ABC141@servername <<EOF
   cd ../ABC141_01/
   put $fname
   quit
   EOF
   mv $fname ./archive/$(basename $fname)-$(date +%Y%m%d-%T)
done

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

share|improve this 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
add comment

closed as not constructive by womble, Michael Hampton, Scott Pack, HopelessN00b Genius of network, 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.

2 Answers

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
add comment

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
add comment

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