Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I need to execute scp command without using expect command in script.

How to use scp with password? I have tried with following code.

HOST=lnx1
USERNAME=user
PASSWORD=pwd
PATH=/sample/data/
FILE=$1
scp $FILE $USERNAME:'$PASSWORD'@$HOST:$PATH       
sshpass -p '$PASSWORD' scp $FILE $USERNAME@:$PATH

Error messages:

scp: command not found
sshpass: command not found

How to achieve this thing?

share|improve this question
    
Your script has only 12 lines and the error is on line 16. –  Anthon Sep 19 '14 at 9:05
    
And you should not append to your question, the first one is answered and solved. Make a new one for the second otherwise the answers make no sense for the question and or title changes, so please roll back to revision 2 of your question. –  Anthon Sep 19 '14 at 9:10
    
user should be your actual user name. –  terdon Sep 19 '14 at 12:59
    
@terdon if the "user" would be a problem, that would give a "permission denied, please try again" –  Anthon Sep 19 '14 at 14:58
4  
I rolled back this question to its original version. Once you receive an answer that solves your initial problem, accept it and then post a new question to pursue it further. Editing the original one in this way renders the existing answers irrelevant. –  terdon Sep 19 '14 at 15:05

1 Answer 1

up vote 3 down vote accepted

You have set your PATH variable to /sample/data. The previous contents of the PATH variable have been overwritten with this. As a result, your script looks in /sample/data for scp and sshpass, fails to find them there, and gives you the error messages that you are seeing.

Try changing the PATH variable name to a different name, e.g:

REMOTE_PATH=/sample/data/

scp $FILE $USERNAME:'$PASSWORD'@$HOST:$REMOTE_PATH

sshpass -p '$PASSWORD' scp $FILE $USERNAME@:$REMOTE_PATH

If that doesn't work, try putting the full path name to scp and sshpass in your script.

share|improve this answer
    
Thanks for your time. I have updated the question. please look on it. Am getting "ssh: user: Name or service not known lost connection". –  Vasu Sep 19 '14 at 8:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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