Spawn command not found

Phi picture Phi · Jan 16, 2014 · Viewed 33.9k times · Source

I have an error trying to run a .sh file

line 2: spawn: command not found
": no such file or directory
bash.sh: line 3: expect: command not found
bash.sh: line 4: send: command not found
#!/usr/bin/expect -f
spawn sftp -o IdentityFile=MyFile.ppk [email protected]
expect "XXX.XXX.XXX.XXX.gatewayEnter passphrase for key 'MyFile.ppk.ppk':"
send "myPassword"

Any idea why it happens?

Answer

glenn jackman picture glenn jackman · Jan 16, 2014
  1. that is an expect script, so ".exp" would be an appropriate file extension: mv bash.sh sftp.exp
  2. do not launch it like bash bash.sh or sh bash.sh. Do this:
    1. make the program executable: chmod a+x sftp.exp
    2. launch it with ./sftp.exp or /path/to/sftp.exp or move it to a directory in your $PATH and launch it just with sftp.exp
  3. after you send "myPassword" you have to "hit enter": send "myPassword\r"
  4. while developing an expect program, add exp_internal 1 to the top.

Good luck, and come back with further questions.