Sftp with spawn - can't execute


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sftp with spawn - can't execute
# 1  
Old 07-25-2016
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:

Code:
#!/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:

Code:
[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



Moderator's Comments:
Mod Comment Please use code tags as required by forum rules!

Last edited by RudiC; 07-25-2016 at 09:39 AM.. Reason: Added code tags.
# 2  
Old 07-25-2016
Did you try not to "source" the file (. test.sh) but to execute it (./test.sh), given it has execute permission?
# 3  
Old 07-25-2016
Hi,

thanks for your reply!

Here is the result:

Code:
[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



Moderator's Comments:
Mod Comment Use code tags, thanks.

Last edited by zaxxon; 07-25-2016 at 09:59 AM..
# 4  
Old 07-25-2016
Quote:
Originally Posted by festerbg
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.
Code:
which expect

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

Thanks,
R. Singh

Last edited by RavinderSingh13; 07-25-2016 at 09:59 AM..
# 5  
Old 07-25-2016
Hello,

Code:
[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
# 6  
Old 07-25-2016
Quote:
Originally Posted by festerbg
Hello,
Code:
[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.
Code:
cat -v Input_file(Your_script_name_here)

Thanks,
R. Singh
# 7  
Old 07-25-2016
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Windows & DOS: Issues & Discussions

Sftp batch file not able to execute

I have a windows batch file to connect from Server A (Windows) to Server B (UNIX) via sftp to get a file. The script is as below: sftpg3 -oStrictHostKeyChecking=no -oIdentityFile=EAPIINSTADM_hostnameA ftpeapsg@hostnameB lcd D:\APPBASE\EAPSG\GEMSSG get GENUOBGW1 /sftp/ftphrssg/HRSSG/EAPSG exit... (5 Replies)
Discussion started by: userguy
5 Replies

2. UNIX for Beginners Questions & Answers

Execute a script after SFTP transfer

Hi All, I am having an issue with the script execution. I am having a SFTP process that send files to a location . I want to execute a script once it transfer the file to that location. Right now I am leveraging autosys file watcher to do that. Is there any way like MFT PPA that can execute... (2 Replies)
Discussion started by: arunkumar_mca
2 Replies

3. Shell Programming and Scripting

Spawn sftp and Shell commands

Hi everyone, I'm no killer in shell scripting, that is why I've searched and found a little script that explained how to do what I wanted to do : a FTP transfer from distant servers. I adapted it cause as such, it didn't work. As I needed to do some very simple shell commands (erase and... (2 Replies)
Discussion started by: mederik
2 Replies

4. Shell Programming and Scripting

Using expect command, spawn will not start sftp process

Hi all, I have a script that runs sftp with expect so I can login and send a file in a cronjob. I've installed this on a couple other servers and it has been fine. However, this time on this machine, it seems to be giving me an issue. It won't move past the spawn sftp command and return a... (3 Replies)
Discussion started by: ltyrrell
3 Replies

5. Shell Programming and Scripting

i want to execute shell script on remote server with in sftp session

Hi, I want to execute shell script with in sftp session for remote server. like i have a shell script test.sh that is on local server.i want to execute that script on remote server sftp user@192.168.56.10 sftp> test.sh ---execute for remote server not for local server. sftp... (3 Replies)
Discussion started by: SAUD PASHA
3 Replies

6. Shell Programming and Scripting

how to execute a program present on another server using SFTP in perl

Hi, I want to execute a program which is present on another server. i want to use SFTP in perl, is it possible? how ? thanks. (1 Reply)
Discussion started by: anandgodse
1 Replies

7. Shell Programming and Scripting

Execute shell script within sftp session

Hi all , can any one tell me how to run a script within a sftp session. let me tell u in bit clear way : After I connected to sftp location , cd ing to some directory then I need to execute a one script. Please tell me if u have any idea on this . Looking forward to your reply guys... (1 Reply)
Discussion started by: sravan008
1 Replies

8. Shell Programming and Scripting

execute shell commands with in sftp

Hi All, Please let me know how do I execute some of the shell commands like cat, find ,grep within sftp. Any help in this regard would be greatly appreciated. Thanks, (5 Replies)
Discussion started by: tommy1
5 Replies

9. Shell Programming and Scripting

To execute next UNIX command after ending SFTP process.

Hi, I am trying to run a simple UNIX command after i successfully executed SFTP command as shown below. ----------------------------------------- echo 'Step-1' sftp -vvv -b path exit echo 'Step-2' ------------------------------------------ In above script it executes from the 1st... (3 Replies)
Discussion started by: gautamc
3 Replies
Login or Register to Ask a Question