gmclean has asked for the wisdom of the Perl Monks concerning the following question:

This may be more of an operating system question but I will ask anyway. The code below grabs an image from the web and saves it as a file. This works on windows but on my hosting company's Linux machine it does not produce a file. I created another simple script to create a write text to a file and it works so I think I have permissions correct. Any suggestions?
#!/usr/bin/perl # Create a user agent object use LWP::UserAgent; my $ua = LWP::UserAgent->new; my $url = 'http://www.nwweather.com/images/realwind-animate1.gif'; my $response = $ua->get($url, ':content_file' => 'testimage.gif'); # Pass request to the user agent and get a response back # Check the outcome of the response if ($response->is_success) { print $url; } else { print $response->status_line, "\n"; }
Thanks, George

Replies are listed 'Best First'.
Re: linux file creation
by bobf (Monsignor) on May 31, 2007 at 05:56 UTC

    The file (testimage.gif) may not have been created in the directory you expected. Are you sure the working directory is what you think it is? Perhaps the file exists happily elsewhere. (You could avoid this question by specifying a full path rather than only a filename.)

    Secondly, you may be interested in LWP::Simple's getstore() method. It is very similar to what you're using now (in fact, it's a wrapper over LWP::UserAgent), but you may find it easier to use.

      Thanks for the suggestions. I am not sure how to determine the working directory. I tried using pwd when in the directory where script reside to get the full path and added that to the file name. This still did not work. My guess is that due to my lack of Linux experience I am missing something simple. Here is my altered script. Any suggestions would be greatly appreciated.
      #!/usr/bin/perl # Create a user agent object use LWP::UserAgent; my $ua = LWP::UserAgent->new; my $url = 'http://www.nwweather.com/images/realwind-animate1.gif'; my $response = $ua->get($url, ':content_file' => '/kunden/homepages/ +40/d176746031/htdocs/NWWX/CamScripts/testimage.gif'); # Pass request to the user agent and get a response back # Check the outcome of the response if ($response->is_success) { print $url; } else { print $response->status_line, "\n"; }
Re: linux file creation
by quester (Vicar) on May 31, 2007 at 05:59 UTC
    It works for me on Linux. I would strongly suspect that if you check the default directory on the target machine, the userid that your script is running under can't write to it. Other likely causes are that it's out of disk space, or quota. You might try having your script chdir to another directory, say /tmp, to help track it down.