Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spawn command not found

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?

like image 692
Phi Avatar asked Dec 01 '22 02:12

Phi


1 Answers

  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.

like image 69
glenn jackman Avatar answered Dec 04 '22 06:12

glenn jackman