LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices



Reply
 
Search this Thread
Old 05-16-2008, 09:33 AM   #1
Lazypete
LQ Newbie
 
Registered: May 2008
Posts: 7

Rep: Reputation: 0
Capturing output from background FTP command


Hi everyone

I wrote a small script that connect to a FTP to get some files, pass them to a java apps someone else wrote and once converted, send them back to that FTP.

I want to capture the output of the FTP command I execute so I can send back error message when something wrong happen. (unable to connect, dns error and such.)

The script is ran from a normal user account throught cron every minutes. ( 55 times / hours actually )

I write a FTP command script on the fly, then launch it like that:

script -c autogenftp.sh ftpoutput.txt

The problem is that the damn script command hang once in a while.
Not everytime.. vary from no hanging in a hour to as much as hanged 12 times in the hour.
And I end up with a whole lot of hung process that polute my server.

I tried many things

sh autogenftp.sh 2&>1 ftpoutput.txt
sh autogetftp.sh | tee ftpoutput.txt
sh autogetftp.sh 1> ftpoutput.txt

But this doesnt work I only get error message like
output to local-file: ./list [anpqy?]? 'EPSV': command not understood
(ie I only get FTPs error message no good message)

Yeah I know...
For the moment I run this once an hour to clean them up
ps axf | grep "script -c /home/user" | awk '{ print $1 }' | xargs kill -9
But thats not sexy in a work environment.
I want something that works.. not something I need a patch for it to work..

Anyone knows another way to capture a FTP output ?

This is what I need to capture (I ran the script manually instead of in cron)

Connected to someserver
220 Microsoft FTP Service
331 Password required for user.
230 User user logged in.
Remote system type is Windows_NT.
250 CWD command successful.
250 CWD command successful.
250 CWD command successful.
output to local-file: /home/user/conversion/temp/ftplist-463290000 [anpqy?]? 500 'EPSV': command not understood
227 Entering Passive Mode (10,99,0,182,18,31).
125 Data connection already open; Transfer starting.
226 Transfer complete.
221



Im running SLES 9 (Suse Linux Enterprise Server)

I welcome any comment or suggestion.
Thanx for your time everyone
 
Old 05-16-2008, 03:04 PM   #2
rtspitz
Member
 
Registered: Jan 2005
Location: germany
Distribution: suse, opensuse, debian, others for testing
Posts: 307

Rep: Reputation: 32
Code:
sh autogenftp.sh >./ftpoutput.log 2>&1
 
Old 05-20-2008, 09:10 AM   #3
Lazypete
LQ Newbie
 
Registered: May 2008
Posts: 7

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by rtspitz View Post
Code:
sh autogenftp.sh >./ftpoutput.log 2>&1
Didn`t work either.

I don`t know why everywhere I look it says something like that, but it doesn`t work with either FTP or SuSE

Anyone has other suggestions ?
 
Old 05-20-2008, 09:34 AM   #4
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
Use option -v of ftp
Quote:
-v Verbose option forces ftp to show all responses from the remote server, as well as report on data
transfer statistics.
then redirect standard output and standard error at your desire. To redirect both to the same file, the way suggested by rtspitz is the correct one.
 
Old 05-20-2008, 09:51 AM   #5
rtspitz
Member
 
Registered: Jan 2005
Location: germany
Distribution: suse, opensuse, debian, others for testing
Posts: 307

Rep: Reputation: 32
Have you tried "curl" ?

I don't know if ordinary ftp clients are good for scripts, curl is meant to be used for that.

ftp-upload:

Code:
curl --verbose --user username:passord --upload-file /tmp/some_file ftp://hostname:21/file_goes_here/
ftp-download:
Code:
curl --verbose --user username:password ftp://hostname:21/somefile --output somefile
 
Old 05-21-2008, 02:24 PM   #6
Lazypete
LQ Newbie
 
Registered: May 2008
Posts: 7

Original Poster
Rep: Reputation: 0
All hail rtspitz

Looking good so far!
Thats what I was looking for rtspitz!
Thank you.

I'll keep you posted but so far so good.

I only needed to change and use something else and curl seems to do what I needed.

Thank you very much!
 
Old 05-22-2008, 11:41 AM   #7
Lazypete
LQ Newbie
 
Registered: May 2008
Posts: 7

Original Poster
Rep: Reputation: 0
Thanx you all

curl works great!

I want to thank all of you for your ideas and suggestions.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl: Running Command line apps in background and capturing output s0l1dsnak3123 Programming 8 03-28-2008 02:24 PM
expect_out(buffer) is not capturing all output from a Cisco IOS command eentonig Programming 1 01-30-2008 08:29 AM
Shell scripting, capturing the output... Elric of Grans Linux - General 6 02-16-2007 12:39 AM
capturing output of 'faad -i'.... bulliver Programming 3 09-18-2005 07:51 PM
script is capturing output.... wedgeworth Linux - Software 7 10-20-2003 06:11 PM


All times are GMT -5. The time now is 04:32 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration