Interspersed comments.

On Mon, 3 Jun 2002 15:58:44 -0400 Joel Laforest <[EMAIL PROTECTED]> wrote:

> Hello all, I have the following simple procedure which works fine for
> the 15 other identical servers for not for this new server that I
> obtained:
> 
> 
> #!/usr/bin/perl
> use strict;
> use DBI;
> use DBD::Oracle;

You don't need to 'use DBD::Oracle;'.  DBI does that for you if necessary.

> use Mail::Sender;
> 
> sub create_file
> #__________________________________________________________
> {
>  my ($file,$content)=@_;
> 
> if (!open(Q, "$file")) {

A better test would be ( -f $file ).  open() will fail if you don't have
read permission.  The quotes (") aren't needed around $file.

>         open(Q, ">$file") ;
>         print Q "$content";
>         close(Q);
> 
> }else{
> unlink("$file");

The quotes (") aren't needed around $file.  You should also close Q
before attempting to unlink it.  Some systems don't let you unlink open
files.

> system ("chmod 777 ./$file");

Perl has a chmod() function, you don't need to use system().  As well as
being faster, chmod() sets $! so you get a better indication if something
fails.  If you are concerned that unlink() might fail, you should call
chmod() before unlink().

> open(Q, "> $file") ;
>         print Q "$content";
>         close(Q);
>      }
> system ("chmod 744 ./$file");
> }
> 
> create_file("joel_test","hello");
> 0;
> 
> 
> 
> This script when run from the command line works fine but from the cron
> create the file empty!!!! Has anybody experienced this problem before,

As BAO mentioned, the directory you run in from cron is unlikely to be the
same one as you are in when running from the command line.

-- 
Mac :})
** I normally forward private questions to the appropriate mail list. **
Ask Smarter: http://www.tuxedo.org/~esr/faqs/smart-questions.html
Give a hobbit a fish and he eats fish for a day.
Give a hobbit a ring and he eats fish for an age.


Reply via email to