?
Solved

ftp fails to redirect output??

Posted on 2009-04-08
19
Medium Priority
?
849 Views
Last Modified: 2013-11-17
I have a simple ftp command that ftp's a file from one server to another and redirects its output to a log file. I use a .netrc file with the machine name and put command in it. Problem is, it only writes the log file "sometimes". It's totally intermittant. Any ideas what could case this? Here's the ftp command:
ftp svrName > /myDir/myLogFile

.netrc file:

#svrName start
machine svrName login xxxx password xx macdef init
put /myDir/myFile targetDir/myFile
quit
0
Comment
Question by:shaner74
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 5
  • 4
  • +1
19 Comments
 
LVL 46

Expert Comment

by:Kent Olsen
ID: 24097809
Hi Shaner,

You may have multiple tasks trying to write that output file, which means that they're stepping on each other.

I'd redirect the output to a temporary file, then append it to the LogFile.

You could append it directly to the log file, but that runs the risk of messages from different tasks getting interwoven.  That may be chronologically correct, but not obvious to someone reading the log file.


Good Luck,
Kent
0
 

Author Comment

by:shaner74
ID: 24098165
But nothing is being written to the log file at all. It's just remaining unchanged. It's really odd because it's so intermittent.
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 24098611
can you give example of successful and failed to log
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:shaner74
ID: 24098824
The log file is cleared out before ftp'ing anything. Upon a success, the log file will look something like this:
Connected to 172.21.1.103.
220 myTest FTP server (Version 4.1 Mon May 26 21:40:36 CDT 2003) ready.
331 Password required for xxxx.
230 User xxx logged in.
200 Type set to I.
200 PORT command successful.
150 Opening data connection for testFile.
226 Transfer complete.
225280 bytes sent in 0.06821 seconds (3225 Kbytes/s)
local: testFile remote: testFile
221 Goodbye.

On "failure", the log file is just empty.
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 24098884
how  do you run the ftp and how do you know that it run when the file is empty ?
0
 

Author Comment

by:shaner74
ID: 24098952
The ftp is run from another program. I know it was successful because the file was ftp'd to the server. It's just that for some reason it doesn't write the log file??
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 24099053
is it run as a crontab job? can you elaborate more on the other program?
0
 

Author Comment

by:shaner74
ID: 24099139
Oh sorry...the other program is run from a database called UniVerse. I use a UniVerse BASIC Execute statement and invoke the shell with a -c so it takes the string as a command. It's run like so:
EXECUTE "sh -c 'ftp ":SVR:" > ":THE.DIR:"/myLogFile"
which translates to:
EXECUTE "sh -c 'ftp svrName > /myDir/myLogFile'"

0
 
LVL 46

Expert Comment

by:Kent Olsen
ID: 24099559
Hi shaner,

Are the symptoms consistent with how the command is run?  That is, does running the command by hand always generate a logfile but running it from your program not generate a logfile?


Kent
0
 

Author Comment

by:shaner74
ID: 24099585
No, running it from the program generates the log file "sometimes".  I'll say, 50% of the time a logfile is generated. This process runs at night so it's been extremely diffcult to troubleshoot.
0
 
LVL 46

Expert Comment

by:Kent Olsen
ID: 24099655
Does more than one process write to that logfile?

I'm wondering if the fundamental issue isn't that the output is buffered and that several tasks have their own buffers.


Kent
0
 

Author Comment

by:shaner74
ID: 24099724
Hi...no it's just this one process that writes to the log file.
0
 
LVL 46

Expert Comment

by:Kent Olsen
ID: 24099792

How do you pipe the commands to the ftp client?

What happens if you wrap the FTP statement in its own script, have the script redirect the output to the logfile, and just call the script from your VB code?


Kent
0
 

Author Comment

by:shaner74
ID: 24099999
Kent,
I thought about doing that. Creating a script that does all the work and then just call the script from uv basic. I just can't think of a reason why that method would always succeed vs. the .netrc method??
0
 
LVL 46

Expert Comment

by:Kent Olsen
ID: 24100119
Normally, I think of a unix shell as a unix shell.  There's just not a lot of magic there.

It's just an educated guess, but it may be the the UV Basic EXECUTE processor is trying to capture the output of the script that you're trying to redirect.  Odd factors like buffer size, output size, etc. may change slightly between executions of the script and that causes the intermittent difference in what you see.  If EXECUTE is trying to implement the redirect that the shell is also redirecting, really weird things will happen.

You should be able to test this.  Run a modified version of the script a dozen times that you know produces less output than what you normally see logged.  The run it again with results that you know produce more output.  It would be nice if you could pick exact character counts, but it's probably not worth that much trouble.

Kent
0
 

Author Comment

by:shaner74
ID: 24100978
hmm? You have a point there Kent. The EXECUTE command in uv has a CAPTURING clause in it that you can use to return any output to the screen. I'm guessing it probably always attempts a capture regardless of that clause being used or not. It could be the execute is grabbing the output before it's redirected, or just plain messing it up somehow. What I'm going to try is to eliminate the ftp redirection, capture the output, then manually write a log file forcing a direct disk write - no buffering. We'll see if that does it.
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 24103691
do you say that the file is empty just because you program cold not capture it or it is really empty and if you check it from command line it is empty?
0
 

Author Comment

by:shaner74
ID: 24106864
it's really empty. Nothing is redirected to the file by ftp.
0
 
LVL 9

Accepted Solution

by:
pauloaguia earned 2000 total points
ID: 24868019
I've found this question while looking for the solution for a similar problem myself.
In my case I was using cron to run the script. I never got output when the script run through cron although it worked perfectly when executed from the command line.


Eventually I found the answer to my problem on my own:

ftp -v ...
The -v flag will make ftp always display the output. Can't really say why I didn't think of that sooner (at least I found a lot of useful things in those 5 hours of research).

Maybe this solves your problem, if you still have it?
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Suggested Courses
Course of the Month10 days, 6 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question