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

I my shell script, I am trying to remove password prompt for scp command (as given in and this is what I have so far :-

expect "password:"
send $sshPassword"\n";

On running the script, I am getting errors

spawn: command not found
send: command not found
interact: command not found

I was also getting error expect: command not found also, then I realised the path to expect was not correct and expect was not installed at all. So, I did yum install expect, corrected the path and the error was gone. But not able to remove the other 3 errors still.

share|improve this question
up vote 6 down vote accepted

You're invoking the script badly.

If you say:

bash scriptname

then the #! line is ignored and bash takes the file as though it were bash instructions. But this is not a bash script, it's an expect script.

The #! line is only ever interpreted by the kernel, when given the script as a command to run in its own right.

Either give the script execute permission, so that you can just invoke ./scriptname, or use the expect command to start the script.

share|improve this answer
  1. make sure you have "expect" tool before, if not, do it

    # apt-get install expect

  2. create the a script file with following content. (# vi /root/scriptfile)

    spawn scp /path_from/file_name user_name_here@to_host_name:/path_to

    expect "password:"

    send put_password_here\n;


  3. execute the script file with "expect" tool

    # expect /root/scriptfile

share|improve this answer

Your Answer


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.