Net/ftp works manually, fails via cron

Hi all,

Ruby 1.8.2
Solaris 10, Linux 2.6.8

I'm experiencing something odd with net/ftp. When I run the following snippet manually it works fine. Running the same snippet under cron seems to fail.

I don't get any messages in the log file. No indication whatsoever that there was a problem. It's just that...nothing happens. There is no file transfer as far as I can see when run via cron.

Any ideas?

Regards,

Dan

# ftptest.rb
require "net/ftp"
include Net

host = "some_host"
log_file = "ftptest.log"

fh = File.open(log_file, "w+")

begin
    ftp = FTP.new(host)
    ftp.login("djberge", "xxxxx")
    ftp.chdir("local")
    ftp.gettextfile("text.temp")
rescue Exception => err
    fh.puts("FTP ERROR: #{err}")
    raise
else
    fh.puts("Got file")
end

begin
    ftp.puttextfile("upload_test.txt")
rescue Exception => err
    fh.puts("FTP ERROR: #{err}")
    raise
else
    fh.puts("Put file")
end

ftp.close
fh.close

Daniel Berger wrote:

Hi all,

Ruby 1.8.2
Solaris 10, Linux 2.6.8

I'm experiencing something odd with net/ftp. When I run the following snippet manually it works fine. Running the same snippet under cron seems to fail.

I don't get any messages in the log file. No indication whatsoever that there was a problem. It's just that...nothing happens. There is no file transfer as far as I can see when run via cron.

Any ideas?

Some questions:

Did you add it to the root user's crontab or your user account's crontab?

When you run it manually and it works, are you running it as root or as yourself?

In the crontab, did you specify the absolute path to both the ruby interpreter and to your script file?

Jamey

Confidentiality Notice: This email message, including any attachments, is for the sole use of the intended recipient(s) and may contain confidential and/or privileged information. If you are not the intended recipient(s), you are hereby notified that any dissemination, unauthorized review, use, disclosure or distribution of this email and any materials contained in any attachments is prohibited. If you receive this message in error, or are not the intended recipient(s), please immediately notify the sender by email and destroy all copies of the original message, including attachments.

Hi all,

Ruby 1.8.2
Solaris 10, Linux 2.6.8

I'm experiencing something odd with net/ftp. When I run the following snippet manually it works fine. Running the same snippet under cron seems to fail.

I don't get any messages in the log file. No indication whatsoever that there was a problem. It's just that...nothing happens. There is no file transfer as far as I can see when run via cron.

Any ideas?

path to ruby is fubar under cron? what's the shebang line and cron line?

Regards,

Dan

# ftptest.rb
require "net/ftp"
include Net

host = "some_host"
log_file = "ftptest.log"

fh = File.open(log_file, "w+")

begin
  ftp = FTP.new(host)
  ftp.login("djberge", "xxxxx")
  ftp.chdir("local")
  ftp.gettextfile("text.temp")
rescue Exception => err
  fh.puts("FTP ERROR: #{err}")
  raise
else
  fh.puts("Got file")
end

begin
  ftp.puttextfile("upload_test.txt")
rescue Exception => err
  fh.puts("FTP ERROR: #{err}")
  raise
else
  fh.puts("Put file")
end

ftp.close
fh.close

-a

···

On Sat, 24 Sep 2005, Daniel Berger wrote:
--

email :: ara [dot] t [dot] howard [at] noaa [dot] gov
phone :: 303.497.6469
Your life dwells amoung the causes of death
Like a lamp standing in a strong breeze. --Nagarjuna

===============================================================================

Jamey Cribbs wrote:

Daniel Berger wrote:

Hi all,

Ruby 1.8.2
Solaris 10, Linux 2.6.8

I'm experiencing something odd with net/ftp. When I run the following snippet manually it works fine. Running the same snippet under cron seems to fail.

I don't get any messages in the log file. No indication whatsoever that there was a problem. It's just that...nothing happens. There is no file transfer as far as I can see when run via cron.

Any ideas?

Some questions:

Did you add it to the root user's crontab or your user account's crontab?

When you run it manually and it works, are you running it as root or as yourself?

In the crontab, did you specify the absolute path to both the ruby interpreter and to your script file?

Nope, whoops, that was it. I think I goofed the crontab, too, which is why I got no error message.

Sorry for the noise.

Dan

Daniel Berger wrote:

Nope, whoops, that was it. I think I goofed the crontab, too, which is why I got no error message.

Handy tip: Always use Logger for cronned scripts.

mathew
[ "It did what? Let me check the log..." ]

···

--
<URL:http://www.pobox.com/~meta/&gt;
          WE HAVE TACOS