Spawn: command not found

Dear Concern,

I want to run following script in RHEL 6.3.

[biuser@blbidb01 daily_bkash_itopup_detail]$ cat sftp_upload.sh
#!/usr/bin/expect
spawn sftp -oPort=434 bkashtopup@172.16.252.59
expect "*?assword:*"
send "bkashtopup1234\n"

send "lcd /BI/application/report/script/daily/daily_bkash_itopup_detail\r"
expect sftp>

send " mput *.gz\r"
expect sftp>

send "exit\r"
expect eof

When try to execute the command in debug mode, got followg error message.
Please help me in this issue.

[biuser@blbidb01 daily_bkash_itopup_detail]$ sh -x sftp_upload.sh
+ spawn sftp -oPort=434 bkashtopup@172.16.252.59
sftp_upload.sh: line 2: spawn: command not found
+ expect '*?assword:*'
couldn't read file "*?assword:*": no such file or directory
+ send 'bkashtopup1234\n'
sftp_upload.sh: line 4: send: command not found
+ send 'lcd /BI/application/report/script/daily/daily_bkash_itopup_detail\r'
sftp_upload.sh: line 6: send: command not found
sftp_upload.sh: line 7: syntax error near unexpected token `newline'
sftp_upload.sh: line 7: `expect sftp>'

With Best Regards,
Md. Abdullah-Al Kauser

---------- Post updated at 02:19 PM ---------- Previous update was at 01:20 PM ----------

Dear concern,

[root@blbidb01 ~]# which expect
/usr/bin/expect
[root@blbidb01 bin]# rpm -qa|grep expect
pexpect-2.3-6.el6.noarch

With Best Regards,
Md. Abdullah-Al Kauser

---------- Post updated at 02:47 PM ---------- Previous update was at 02:19 PM ----------

Dear concern,

Correction Please.

[root@blbidb01 ~]# rpm -qa |grep expect
pexpect-2.3-6.el6.noarch
expect-5.44.1.15-4.el6.x86_64

Instead of using the expect third-party brute forcing tool, you should be pre-arranging passwords with keys. This will allow you to remove the password from the script, remove the expect junk, and work much more reliably.

Hi.

I suggest:

#!/usr/bin/expect --

noting the minus signs. See man expect, Usage

Best wishes ... cheers, drl

Try to invoke your expect script like this, so that the first line in the script can take effect:

./sftp_upload.sh

If you run it like sh sftp_upload.sh or sh -x sftp_upload.sh you are overriding that important first line.

1 Like