Problem in SFTP using heredoc


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem in SFTP using heredoc
# 1  
Old 03-16-2011
Problem in SFTP using heredoc

Hi,
I'm having heredoc to get files from ftp server.

Code:
#!/bin/bash
/export/opt/SCssh/3.7.1_C0/bin/sftp csi@192.168.1.100 <<GET_FILES
lcd /WEBSERVER_LINK/data_logs/
ls -l pub/csidata/GeneralAppFields_8_1_Feed.out pub/csidata/CtcCatalog_7_3_3_Feed.out
get pub/csidata/GeneralAppFields_8_1_Feed.out
get pub/csidata/CtcCatalog_7_3_3_Feed.out
quit
GET_FILES

When I execute this script, first command lcd only getting executed. Remaining commands are not getting executed. If I run these commands explicitly in sftp command prompt, all the commands are getting executed fine. I don't know why only one command is working and it is coming out of the script without executing other commands in heredoc.

Also I'm not getting any error while running the script.

Have any one faced the same issue before? Please reply why it is getting out when execute first command?

Last edited by pludi; 03-16-2011 at 09:16 AM.. Reason: code tags, please
# 2  
Old 03-16-2011
I can't see any problem in this script. Maybe, if you have another version of ssh/sftp on another box, try the script out there to check if that version behaves different. You could also check with vi, using :set list, if there is something awkward in this file after the line including that lcd. You could also try it with another shell maybe.

I tried it with bash and openssh on a Debian GNU Linux and it behaved as expected.
# 3  
Old 03-16-2011
Quote:
ls -l pub/csidata/GeneralAppFields_8_1_Feed.out pub/csidata/CtcCatalog_7_3_3_Feed.out
The above command is a unix command not a ftp command. It will try to output a directory listing to a named file.

Try as two ftp directory list commands:
Code:
ls pub/csidata/GeneralAppFields_8_1_Feed.out
ls pub/csidata/CtcCatalog_7_3_3_Feed.out

# 4  
Old 03-16-2011
Methyl is correct - the rest of the script should continue executing though.
# 5  
Old 03-16-2011
sftp version :
Code:
/export/opt/SCssh/3.7.1_C0/bin/sftp: SSH Tectia Server 4.4.8 on sparc-sun-solaris2.8
Build: 21

Also I forgot to mention in my previous post that, if we use commands in batch file and execute sftp it is working fine.

Script :
Code:
#!/bin/bash
 
 commands_get_files="get_files"
 /export/opt/SCssh/3.7.1_C0/bin/sftp -B $commands_get_files csi@192.168.1.100
 
cat get_files
lcd /WEBSERVER_LINK/data_logs/
ls -l pub/csidata/GeneralAppFields_8_1_Feed.out pub/csidata/CtcCatalog_7_3_3_Feed.out
get pub/csidata/GeneralAppFields_8_1_Feed.out
get pub/csidata/CtcCatalog_7_3_3_Feed.out
quit

When I run this script I'm able to get files from ftp server. If I put commands in batch file it is working fine. If I use heredoc, it's not working. I can go for batch mode design but I have to maintain lot of batch files. So I don't want to go for that option.

Moderator's Comments:
Mod Comment You were asked by pludi to use code tags - you got a PM with a guide how to, thanks.

Last edited by zaxxon; 03-16-2011 at 10:44 AM.. Reason: code tags
# 6  
Old 03-16-2011
Is using ssh and/or scp instead an option?
# 7  
Old 03-16-2011
In case sftp automation required, -b option is recommended to use for sftp batch mode.
Put all those command in a file and use -b file while invoking sftp.
It doen't work EXACTLY as ftp AFAIK.

Code:
     -b batchfile
             Batch mode reads a series of commands from an input batchfile instead of stdin.  Since it lacks user interaction it should be used in conjunction
             with non-interactive authentication.  A batchfile of '-' may be used to indicate standard input.

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Information on heredoc

Hi , I am using ksh on Aix 7.1 and found the below code in a script which is a bit confusing to me, any help will be appreciated <<comments put ${pathforfiles}/${ftpfilename} put ${logs}/${filename}.sch put ${logs}/${filename}.tgr comments I have searched for information on heredoc but... (2 Replies)
Discussion started by: zulfi123786
2 Replies

2. UNIX for Beginners Questions & Answers

SFTP problem

i have a problem no a dream :) i have a list and i want to do : cat lista_olo for file in `cat list` do sftp myuser@myip << EOF ls -l mydir/$file/ EOF but there is an error . Syntax error at line 11 : `<' is not matched How can i do ? Regards. (1 Reply)
Discussion started by: Francesco_IT
1 Replies

3. Shell Programming and Scripting

How To Concatenate Two Commands in script using heredoc?

Hello, I am trying to place two commands in heredoc below is the snippet if ;then actionOnTux="$actVerb" else actionOnTux="$actVerb" fi echo "Performing ACTION: $action on $tux@$srv .....\n" if ; then ... (5 Replies)
Discussion started by: kataria.anand
5 Replies

4. Shell Programming and Scripting

Problem with sftp

I have an sftp script which is uploading file into a directory which is not specified wth the cd command . For example: sftp sftpserver >>lcd /abc >>cd /tmp/bef >> put /abc/abc.txt /tmp/bef/abc.txt Uploading file from /abc/abc.txt to /xyz/wxy/tmp/bef/abc.txt >>quit The file is getting... (2 Replies)
Discussion started by: NP1
2 Replies

5. Shell Programming and Scripting

Echo multi-line string via heredoc syntax

$ cat bashtest #!/usr/local/bin/bash echo <<<"EOF" line1 line2 line3 EOF $ ./bashtest ./bashtest: line 3: line1: command not found ./bashtest: line 4: line2: command not found ./bashtest: line 5: line3: command not found ./bashtest: line 6: EOF: command not found What am i doing... (4 Replies)
Discussion started by: urello
4 Replies

6. Shell Programming and Scripting

Calling sqlplus from Korn shell heredoc issue

Hi, I am facing an issue wherein some temporary files (here docs) are getting created in /tmp and are not getting deleted automatically. When i check the list of open files with below command i can see one file is getting appended continuously.(In this case /tmp/sfe7h.34p) The output is... (4 Replies)
Discussion started by: Navin_Ramdhami
4 Replies

7. Shell Programming and Scripting

Variables in heredoc

I currently use this message to send e-mails in a script but I would also like to save the output of this code to a file as well while preserving the variables. What's the easiest way to accomplish this? #Sending mail notification when=`/bin/date` /usr/sbin/sendmail -t >2 <<-EOM... (2 Replies)
Discussion started by: woodson2
2 Replies

8. Shell Programming and Scripting

heredoc error check

Hi, Is there any way to check the error in heredoc? Code: /export/opt/SCssh/3.7.1_C0/bin/sftp -B - csi@192.168.1.100 <<FTP lcd /WEBSERVER_LINK/data_logs/ ls pub/csidata/GeneralAppFields_8_1_Feed.out get pub/csidata/GeneralAppFields_8_1_Feed.out quit FTP Now I want to check... (1 Reply)
Discussion started by: bheeshmaraja
1 Replies

9. Shell Programming and Scripting

HEREDOC with fdisk

Hi folks What I'm trying is to build a partitioning script. I can pass a HEREDOC to fdisk just fine. Like this: fdisk /dev/sda << EOF p q EOF but I don't know how to put that HEREDOC into a varible to pass it to fdisk. This is what I have tried so far (no luck) #!/bin/bash ... (3 Replies)
Discussion started by: latenite
3 Replies

10. Cybersecurity

sftp problem

Hi, I'm in the process of writting some scripts using sftp2 on a HP UX 11.11 machine. I've found that when I do an 'ls' command , even when in batch mode, it asks for me to 'press any key to continue or q to quit' after a screenful of data. Of course in batch mode this cause the script to hang.... (0 Replies)
Discussion started by: sudojo
0 Replies
Login or Register to Ask a Question