Spawn command not found
- that is an expect script, so ".exp" would be an appropriate file extension:
mv bash.sh sftp.exp
- do not launch it like
bash bash.sh
orsh bash.sh
. Do this:- make the program executable:
chmod a+x sftp.exp
- launch it with
./sftp.exp
or/path/to/sftp.exp
or move it to a directory in your $PATH and launch it just withsftp.exp
- make the program executable:
- after you
send "myPassword"
you have to "hit enter":send "myPassword\r"
- while developing an expect program, add
exp_internal 1
to the top.
Good luck, and come back with further questions.
It works OK for me (error from sftp: ssh: Could not resolve hostname XXX.XXX.XXX.XXX: Name or service not known
), though the .sh
extension for an expect (tcl) script is a little off-putting ;-)
Often when this sort of unexplainable/unpredictable behavior happens, it is because the script was edited under windows (notepad.exe), which uses \r\n
to delimit lines. This plays havoc with unix/linux scripts, as only \n
is expected as a line delimiter.
You can use the dos2unix
and unix2dos
utilities to convert between the two formats. As an experiment, I converted your script to "dos" format, and sure enough got a similar error:
ubuntu@ubuntu:~$ unix2dos bash.sh unix2dos: converting file bash.sh to DOS format ...ubuntu@ubuntu:~$ ./bash.sh ": no such file or directoryubuntu@ubuntu:~$ dos2unix bash.sh dos2unix: converting file bash.sh to Unix format ...ubuntu@ubuntu:~$ ./bash.sh spawn sftp -o IdentityFile=MyFile.ppk 500200243@XXX.XXX.XXX.XXXssh: Could not resolve hostname XXX.XXX.XXX.XXX: Name or service not knownCouldn't read packet: Connection reset by peersend: spawn id exp6 not open while executing"send "myPassword"" (file "./bash.sh" line 4)ubuntu@ubuntu:~$