0

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?

6
  • Your script has only 12 lines and the error is on line 16. Commented Sep 19, 2014 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. Commented Sep 19, 2014 at 9:10
  • user should be your actual user name. Commented Sep 19, 2014 at 12:59
  • @terdon if the "user" would be a problem, that would give a "permission denied, please try again" Commented Sep 19, 2014 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. Commented Sep 19, 2014 at 15:05

1 Answer 1

4

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.

1
  • Thanks for your time. I have updated the question. please look on it. Am getting "ssh: user: Name or service not known lost connection". Commented Sep 19, 2014 at 8:56

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.