[tpm] Net::SCP and Net::SFTP modules

Henry Baragar Henry.Baragar at instantiated.ca
Mon Nov 10 09:27:48 PST 2008


On Sunday, November 09 2008 07:10 pm, Richard Dice wrote:
> On Sun, Nov 9, 2008 at 6:23 PM, Henry Baragar
> <Henry.Baragar at instantiated.ca
>
> > wrote:
> >
> > I have been trying to use Net::SFTP:  it works when I run the application
> > from
> > the shell, but not under cron!
>
> Cron as your user, or cron as the system cron?
>
The user is the same in both cases.

> cron provides a huge dearth of environment variables and other things that
> might be set up by your .login or .bashrc file.  
>
I have removed the user .profile and .bashrc files (there is no .login or 
other *sh init files) and successfully run the script by hand.

> My guess is that there is 
> something being provided by an envvar, shell alias, _something_ in your
> personal environment that your Perl program somehow depends upon.  
>
I have put the following command in the user's crontab:
	/bin/bash --login -c 'sftp_script'
with no luck.

> Or it 
> might be something as simple as directory permissions and how they apply in
> the context of the system cron user.  (might be root, might be cron, might
> be something else)
>
> That debugging message hardly seems helpful, as it is telling where in the
> stack of depended-upon modules the failure occurs at. 
>
Agreed, but I was hoping that it behaved the same at other sites and that 
other users would recognize.

> You should build 
> some debugging / error trapping (eval) code around each line in your
> subroutine there to see where the failure actually occurs at from the
> perspective of your program.  From there you can try to figure out how it
> is different when run as yourself and when run as cron.
>
It fails on the following line:
	$sftp->do_write($handle,0,$self->payload);
That is, the file gets opened on the remote server but nothing ever gets 
written to it (i.e. it has a filesize of 0).

It did not seem worthwhile to dig into the guts of Net::SFTP (which has been 
stable for 3 years) until I exhausted the Google and mailing list options.

Regards,
Henry


> Cheers,
>  - Richard


More information about the toronto-pm mailing list