Sftp with spawn - can't execute

Hi All,

I have below script which is just trying to sftp transfer a file to another server with 'expect' option.

I have expect installed on the instance.

Below is the script:

#!/usr/bin/expect

spawn sftp oracle@<HOST>
expect "password:"
send "<mypassword>\n"
expect "sftp>"
send "cd /tmp\n"
expect "sftp>"
send "put /tmp/test.txt\n"
expect "sftp>"
send "exit\n"
interact

But I get this:

[applmgr@psl-hades tmp]$ . test.sh
Starting...
bash: spawn: command not found
Line 2...
": no such file or directory:
bash: send: command not found
": no such file or directory
bash: send: command not found
": no such file or directory
bash: send: command not found
": no such file or directory
bash: send: command not found
: command not found

Any ideas?

Thanks in advance,
Alex

Did you try not to "source" the file ( . test.sh ) but to execute it ( ./test.sh ), given it has execute permission?

Hi,

thanks for your reply!

Here is the result:

[applmgr@psl-hades tmp]$ chmod 777 test.sh
[applmgr@psl-hades tmp]$ ./test.sh
bash: ./test.sh: /usr/bin/expect^M: bad interpreter: No such file or directory

Regards,
Alex

Hello festerbg,

Please use code tags for Inputs/commands/codes you are using into your posts as per forum rules. Could you please run following command to check either expect has been installed into your box or not. Because expect is not a built-in shell utility.

which expect

Please post us the output of above command along with your O.S name.

Thanks,
R. Singh

Hello,

[applmgr@psl-hades tmp]$ which expect
/usr/bin/expect
[applmgr@psl-hades tmp]$ uname -a
Linux psl-hades.patech-cloud.com 2.6.39-400.247.1.el6uek.x86_64 #1 SMP Thu Feb 5 16:06:15 PST 2015 x86_64 x86_64 x86_64 GNU/Linux

Regards,
Alex

Hello festerbg,

Could you please look for control M characters(Garbage characters) as while putting the file from Windows to *NIX operating systems they may come.
Could you please run following command and let us know the output for same.

cat -v Input_file(Your_script_name_here)

Thanks,
R. Singh

Use a reasonable *nix text editor to compose your script so that that DOS line terminator ^M (= \r, <CR>, 0x0D) won't be appended to the line.