Non-interactive FTP within SSH session not working


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Non-interactive FTP within SSH session not working
# 1  
Old 07-14-2011
Error Non-interactive FTP within SSH session not working

Hello everyone!

I am trying to log-in to a remote server over SSH, transfer file1 there, perform some checks, capture the results in file2 and transfer file2 back to my local server - all of this non-interactively. Initially, I tried to do this within a singe SSH session, using the following code --

Code:
#! /usr/bin/ksh

ssh remotehost "
       [[ ! -d /tmp/workDir ]] && mkdir -p /tmp/workDir
       cd /tmp/workDir
       ftp -nv myLocalHost << EOFTP > /dev/null 2>&1
       user myID myPass
       prompt
       mget file1
       bye
       EOFTP

       while read row
       do
              if [[ -d $row ]]
              then
                    echo "$row is present!"
              else
                    echo "$row is missing!" >> file2
              fi
       done < file1

       if [[ -s file2 ]]
       then
              ftp -nv myLocalHost << EOFTP > /dev/null 2>&1
              user myID myPass
              prompt
              mput file2
              bye
              EOFTP
       fi"

While running this piece, I find that the process is stuck after the "bye" in the first FTP sequence. The script is not executing anything after that. So, to troubleshoot, I tried putting the first FTP in one SSH session, and everything after that in another. This time the FTP prompt is getting terminated properly, and the second SSH connection is also successful, but the error being thrown is -
Quote:
ksh[2]: syntax error in line 3: ']]' unexpected
I guess putting all the separate sections of my code (i.e., the first FTP, the checking and the 2nd FTP) in separate SSH sessions would resolve this issue, however, it might not be preferable, as this is part of a much-larger program, which I'm trying to keep as light as possible.

I'm doing this on Solaris platform, using KSH. I've also checked and confirmed that my default shell in the remote host is KSH (though, I'm not sure if that would make any difference).

Please advice. Thanks a lot, in advance!

With regards,
Subu
# 2  
Old 07-14-2011
First off, realize that whitespace may get flattened by cramming it all into one giant "" like that over ssh. It may be treating newlines just as whitespace and cramming multiple lines together. A here-document wouldn't do that, but then you'd be making here documents inside here documents...!

Might be time to put all that into a script of its own:

Code:
ssh username@host exec /bin/sh -s ARG1 ARG2 < localfile.sh

ARG1 will be available as $1, ARG2 as $2, etc if you need to pass values into the remote shell.
This User Gave Thanks to Corona688 For This Post:
# 3  
Old 07-15-2011
Thanks a lot, Corona688! Smilie

Putting the instructions in a script worked brilliantly!! Thanks, one more time, for the swift reply!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Issues making SSH non-Interactive

I fire the rsyn command as below: rsync --delay-updates -F --compress --archive -e "/usr/bin/ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" user1@myhost.server.com:/tmp/jarexplorer-0.7.jar /web/admin/data/ The above command get interpreted as below: ssh -vvv -o... (4 Replies)
Discussion started by: mohtashims
4 Replies

2. Shell Programming and Scripting

Non-interactive pkgadd not working.

Inorder to make the pkgadd non-interactive i tried couple of things but both failed. 1. sudo pkgadd -n /u/mont/admin -d /u/mont/dbprd.pkg pkgadd: ERROR: no packages were found in </var/spool/pkg> 2. yes all | sudo pkgadd -a /u/mont/admin -d /u/mont/dbprd.pkg ... (0 Replies)
Discussion started by: mohtashims
0 Replies

3. Shell Programming and Scripting

FTP session not working on cron

Hi, I'm experiencing an issue with creating an ftp session via cron. I am creating an ftp session between a data server and a reporting tool. I have created the script wherein the data server begins the ftp session and puts files into the tool. I have used the .netrc files for this and I run... (10 Replies)
Discussion started by: robin.b
10 Replies

4. Shell Programming and Scripting

scripting an interactive program session

Hello, I'm looking to script the basic instant messaging program we have in my company, it's called "oi", it's working as follow: # oi $user then we have to launch it... after finding the system of the user it's asking for the message... then on a new line we have to hit ctrl+d I... (2 Replies)
Discussion started by: nomadvisuals
2 Replies

5. Shell Programming and Scripting

SSH non-interactive

Hi, I want to know how to use SSH non-interactively? I am already able to use sftp -b <batch file> user@host so public/private key set-up already is in place. But my supervisor has told me to use SSH now I want to know how it can be done? I want to do something like: done_files=`ssh ls... (7 Replies)
Discussion started by: dips_ag
7 Replies

6. Shell Programming and Scripting

Exit SSH if it is interactive

I am writing an automation that will ssh into hundreds of system and run a few commands. I ll be looping from ip X.X.X.10 to X.X.X.200 I have public key set up ready for "most" of them to run ssh non interactively. However some of the systems in these ip range do not have the public private key... (2 Replies)
Discussion started by: vickylife
2 Replies

7. UNIX and Linux Applications

SSH with Keyboard Interactive

Hi, I am changing the login authentication method from password to keyboard interactive for security purposes. I know this option is kind of add-on for ssh client programs; which explains the best info about option is in this link: User Authentication with Keyboard-Interactive :eek: One of... (4 Replies)
Discussion started by: royalliege
4 Replies

8. HP-UX

ssh session getting hung (smilar to hpux telnet session is getting hung after about 15 minutes)

Our network administrators implemented some sort of check to kill idle sessions and now burden is on us to run some sort of keep alive. Client based keep alive doesn't do a very good job. I have same issue with ssh. Does solution 2 provided above apply for ssh sessions also? (1 Reply)
Discussion started by: yoda9691
1 Replies

9. Shell Programming and Scripting

could not send commands SSH session with Net::SSH::Expect

I am using Net::SSH::Expect to connect to the device(iLO) with SSH. After the $ssh->login() I'm able to view the prompt, but not able to send any coommands. With the putty I can connect to the device and execute the commands without any issues. Here is the sample script my $ssh =... (0 Replies)
Discussion started by: hansini
0 Replies

10. Shell Programming and Scripting

Interactive ftp get/put

Hi All, I'm trying to get this to work but when I execute it I get the following error ./ftp_upload.sh: line 78: syntax error: unexpected end of file. This was working before I expanded the script and had the here document part directly below within a function. Can anyone spot what I've... (5 Replies)
Discussion started by: darrenm
5 Replies
Login or Register to Ask a Question