Loading ...
Sorry, an error occurred while loading the content.

Strange issue with cronjobs

Expand Messages
  • kjhseka
    Hello, I have a strange problem with a script that should be executed by a cronjob. The script would count the number of visits a website receives daily. For
    Message 1 of 8 , Jun 1, 2005
    • 0 Attachment
      Hello,
      I have a strange problem with a script that should be executed by a
      cronjob. The script would count the number of visits a website
      receives daily. For this, it use two files and do the following:

      1) read the yesterday counter value stored in the file tod_cnt.dat
      2) read the file counter.dat, the today counter value
      3) substract yesterday value from today value

      If I execute the script in the server with these commands:

      cd public_html
      cd cgi-bin
      perl puthit.pl

      The script work properly.

      But if I run the cron job with the command

      perl /home/art/public_html/cgi-bin/puthit.pl

      The script generated a set of warnings and give incorrect results, 0
      instead of the number of visits. Why?

      Here's the script:

      #!/usr/bin/perl -w

      use strict;

      print "Content-type: text/plain", "\n\n";

      my ($yday_cnt, # yesterday hits
      $tday_cnt, # today hits
      $nbvisits); # daily visits

      open (YDAY_CNT, "/home/art/public_html/lg/tod_cnt.dat");
      $yday_cnt = <YDAY_CNT>;
      close YDAY_CNT;

      open (CNT, "/home/art/public_html/cgi-bin/counter.dat");
      $tday_cnt = <CNT>;
      close CNT;

      $nbvisits = $tday_cnt - $yday_cnt;

      # Update the today total visits file
      open (TOT_CNT, ">/home/art/public_html/lg/tod_cnt.dat");
      print TOT_CNT $tday_cnt;
      close TOT_CNT;

      open (TDAY_VISITS, ">/home/art/public_html/lg/tdhits.dat");
      print TDAY_VISITS $nbvisits;
      close TDAY_VISITS;

      # Generate output in case of online consultation
      print "<html><head><title>Output generated by puthit.pl, the
      automated visit counter</head></title>";
      print "<body>$tday_cnt<br>$nbvisits<br></body></html>";

      exit(0);


      The warnings are:
      readline() on closed filehandle YDAY_CNT at home/art....., line 12
      readline() on closed filehandle CNT at home/art....., line 16
      use of uninitialized value in subtraction (0) at home/art..., line 19
      idem
      print() on closed filehandle TOT_CNT at /home/art.... line 23
      print() on closed filehandle TDAY_VISITS at /home/art.... line 27
      Use of uninitialized value in concatenation (.) or string
      at /home/art..... line 32


      The output give incorrect results.

      I don't understand these warning and I don't understant why the
      script doesn't work when I execute it via a cron job.

      Can you give me any help?

      Thanks
      Alph
    • prakash
      Make sure you run as the correct owner of that file That is xyz /usr/bin/perl scriptname It should be same as who u run as from the command line.. -prak ...
      Message 2 of 8 , Jun 1, 2005
      • 0 Attachment
        Make sure you run as the correct owner of that file

        That is xyz /usr/bin/perl scriptname

        It should be same as who u run as from the command line..

        -prak



        -----Original Message-----
        From: perl-beginner@yahoogroups.com [mailto:perl-beginner@yahoogroups.com]
        On Behalf Of kjhseka
        Sent: Wednesday, June 01, 2005 1:40 PM
        To: perl-beginner@yahoogroups.com
        Subject: [PBML] Strange issue with cronjobs

        Hello,
        I have a strange problem with a script that should be executed by a
        cronjob. The script would count the number of visits a website
        receives daily. For this, it use two files and do the following:

        1) read the yesterday counter value stored in the file tod_cnt.dat
        2) read the file counter.dat, the today counter value
        3) substract yesterday value from today value

        If I execute the script in the server with these commands:

        cd public_html
        cd cgi-bin
        perl puthit.pl

        The script work properly.

        But if I run the cron job with the command

        perl /home/art/public_html/cgi-bin/puthit.pl

        The script generated a set of warnings and give incorrect results, 0
        instead of the number of visits. Why?

        Here's the script:

        #!/usr/bin/perl -w

        use strict;

        print "Content-type: text/plain", "\n\n";

        my ($yday_cnt, # yesterday hits
        $tday_cnt, # today hits
        $nbvisits); # daily visits

        open (YDAY_CNT, "/home/art/public_html/lg/tod_cnt.dat");
        $yday_cnt = <YDAY_CNT>;
        close YDAY_CNT;

        open (CNT, "/home/art/public_html/cgi-bin/counter.dat");
        $tday_cnt = <CNT>;
        close CNT;

        $nbvisits = $tday_cnt - $yday_cnt;

        # Update the today total visits file
        open (TOT_CNT, ">/home/art/public_html/lg/tod_cnt.dat");
        print TOT_CNT $tday_cnt;
        close TOT_CNT;

        open (TDAY_VISITS, ">/home/art/public_html/lg/tdhits.dat");
        print TDAY_VISITS $nbvisits;
        close TDAY_VISITS;

        # Generate output in case of online consultation
        print "<html><head><title>Output generated by puthit.pl, the
        automated visit counter</head></title>";
        print "<body>$tday_cnt<br>$nbvisits<br></body></html>";

        exit(0);


        The warnings are:
        readline() on closed filehandle YDAY_CNT at home/art....., line 12
        readline() on closed filehandle CNT at home/art....., line 16
        use of uninitialized value in subtraction (0) at home/art..., line 19
        idem
        print() on closed filehandle TOT_CNT at /home/art.... line 23
        print() on closed filehandle TDAY_VISITS at /home/art.... line 27
        Use of uninitialized value in concatenation (.) or string
        at /home/art..... line 32


        The output give incorrect results.

        I don't understand these warning and I don't understant why the
        script doesn't work when I execute it via a cron job.

        Can you give me any help?

        Thanks
        Alph





        Unsubscribing info is here:
        http://help.yahoo.com/help/us/groups/groups-32.html
        Yahoo! Groups Links
      • Brad Lhotsky
        It wouldn t hurt to check to ensure you opened the files. ie: open (YDAY_CNT, /home/art/public_html/lg/tod_cnt.dat ) or die unable to open file: $! ; Make
        Message 3 of 8 , Jun 1, 2005
        • 0 Attachment
          It wouldn't hurt to check to ensure you opened the files.
          ie:

          open (YDAY_CNT, "/home/art/public_html/lg/tod_cnt.dat")
          or die "unable to open file: $!";

          Make sure the cron entry is running with a user that has permissions to
          read and write to your directories :)


          On Wed, Jun 01, 2005 at 08:40:14PM -0000, kjhseka wrote:
          > Hello,
          > I have a strange problem with a script that should be executed by a
          > cronjob. The script would count the number of visits a website
          > receives daily. For this, it use two files and do the following:
          >
          > 1) read the yesterday counter value stored in the file tod_cnt.dat
          > 2) read the file counter.dat, the today counter value
          > 3) substract yesterday value from today value
          >
          > If I execute the script in the server with these commands:
          >
          > cd public_html
          > cd cgi-bin
          > perl puthit.pl
          >
          > The script work properly.
          >
          > But if I run the cron job with the command
          >
          > perl /home/art/public_html/cgi-bin/puthit.pl
          >
          > The script generated a set of warnings and give incorrect results, 0
          > instead of the number of visits. Why?
          >
          > Here's the script:
          >
          > #!/usr/bin/perl -w
          >
          > use strict;
          >
          > print "Content-type: text/plain", "\n\n";
          >
          > my ($yday_cnt, # yesterday hits
          > $tday_cnt, # today hits
          > $nbvisits); # daily visits
          >
          > open (YDAY_CNT, "/home/art/public_html/lg/tod_cnt.dat");
          > $yday_cnt = <YDAY_CNT>;
          > close YDAY_CNT;
          >
          > open (CNT, "/home/art/public_html/cgi-bin/counter.dat");
          > $tday_cnt = <CNT>;
          > close CNT;
          >
          > $nbvisits = $tday_cnt - $yday_cnt;
          >
          > # Update the today total visits file
          > open (TOT_CNT, ">/home/art/public_html/lg/tod_cnt.dat");
          > print TOT_CNT $tday_cnt;
          > close TOT_CNT;
          >
          > open (TDAY_VISITS, ">/home/art/public_html/lg/tdhits.dat");
          > print TDAY_VISITS $nbvisits;
          > close TDAY_VISITS;
          >
          > # Generate output in case of online consultation
          > print "<html><head><title>Output generated by puthit.pl, the
          > automated visit counter</head></title>";
          > print "<body>$tday_cnt<br>$nbvisits<br></body></html>";
          >
          > exit(0);
          >
          >
          > The warnings are:
          > readline() on closed filehandle YDAY_CNT at home/art....., line 12
          > readline() on closed filehandle CNT at home/art....., line 16
          > use of uninitialized value in subtraction (0) at home/art..., line 19
          > idem
          > print() on closed filehandle TOT_CNT at /home/art.... line 23
          > print() on closed filehandle TDAY_VISITS at /home/art.... line 27
          > Use of uninitialized value in concatenation (.) or string
          > at /home/art..... line 32
          >
          >
          > The output give incorrect results.
          >
          > I don't understand these warning and I don't understant why the
          > script doesn't work when I execute it via a cron job.
          >
          > Can you give me any help?
          >
          > Thanks
          > Alph
          >
          >
          >
          >
          >
          > Unsubscribing info is here: http://help.yahoo.com/help/us/groups/groups-32.html
          > Yahoo! Groups Links
          >
          >
          >
          >
          >
          >
          >

          --
          Brad Lhotsky <brad@...>
        • Kris Stitt
          I don t have a full answer for this but I might have a clue or two. I think that cron does not have all of the same settings that a normal user would have. So
          Message 4 of 8 , Jun 1, 2005
          • 0 Attachment
            I don't have a full answer for this but I might have a clue or two. I think
            that cron does not have all of the same settings that a normal user would
            have. So some of you enviromental veriables may not be understood in a cron
            job (pathing etc.)

            I've been calling perl sripts from cron using a shell file, this seems to
            work for me:
            00 6-19 * * 1-5 /usr/local/bin/monthly.sh

            Inside the monthly.sh file is actually the command to run the perl script:

            perl /user/local/bin/monthly.pl

            I'm not sure if any of that makes sense or not. (There is probably a much
            better way to do this.)



            Good Luck,

            -Kris


            ----- Original Message -----
            From: "kjhseka" <kjhseka@...>
            To: <perl-beginner@yahoogroups.com>
            Sent: Wednesday, June 01, 2005 1:40 PM
            Subject: [PBML] Strange issue with cronjobs


            > Hello,
            > I have a strange problem with a script that should be executed by a
            > cronjob. The script would count the number of visits a website
            > receives daily. For this, it use two files and do the following:
            >
            > 1) read the yesterday counter value stored in the file tod_cnt.dat
            > 2) read the file counter.dat, the today counter value
            > 3) substract yesterday value from today value
            >
            > If I execute the script in the server with these commands:
            >
            > cd public_html
            > cd cgi-bin
            > perl puthit.pl
            >
            > The script work properly.
            >
            > But if I run the cron job with the command
            >
            > perl /home/art/public_html/cgi-bin/puthit.pl
            >
            > The script generated a set of warnings and give incorrect results, 0
            > instead of the number of visits. Why?
            >
            > Here's the script:
            >
            > #!/usr/bin/perl -w
            >
            > use strict;
            >
            > print "Content-type: text/plain", "\n\n";
            >
            > my ($yday_cnt, # yesterday hits
            > $tday_cnt, # today hits
            > $nbvisits); # daily visits
            >
            > open (YDAY_CNT, "/home/art/public_html/lg/tod_cnt.dat");
            > $yday_cnt = <YDAY_CNT>;
            > close YDAY_CNT;
            >
            > open (CNT, "/home/art/public_html/cgi-bin/counter.dat");
            > $tday_cnt = <CNT>;
            > close CNT;
            >
            > $nbvisits = $tday_cnt - $yday_cnt;
            >
            > # Update the today total visits file
            > open (TOT_CNT, ">/home/art/public_html/lg/tod_cnt.dat");
            > print TOT_CNT $tday_cnt;
            > close TOT_CNT;
            >
            > open (TDAY_VISITS, ">/home/art/public_html/lg/tdhits.dat");
            > print TDAY_VISITS $nbvisits;
            > close TDAY_VISITS;
            >
            > # Generate output in case of online consultation
            > print "<html><head><title>Output generated by puthit.pl, the
            > automated visit counter</head></title>";
            > print "<body>$tday_cnt<br>$nbvisits<br></body></html>";
            >
            > exit(0);
            >
            >
            > The warnings are:
            > readline() on closed filehandle YDAY_CNT at home/art....., line 12
            > readline() on closed filehandle CNT at home/art....., line 16
            > use of uninitialized value in subtraction (0) at home/art..., line 19
            > idem
            > print() on closed filehandle TOT_CNT at /home/art.... line 23
            > print() on closed filehandle TDAY_VISITS at /home/art.... line 27
            > Use of uninitialized value in concatenation (.) or string
            > at /home/art..... line 32
            >
            >
            > The output give incorrect results.
            >
            > I don't understand these warning and I don't understant why the
            > script doesn't work when I execute it via a cron job.
            >
            > Can you give me any help?
            >
            > Thanks
            > Alph
            >
            >
            >
            >
            >
            > Unsubscribing info is here:
            > http://help.yahoo.com/help/us/groups/groups-32.html
            > Yahoo! Groups Links
            >
            >
            >
            >
            >
            >
            >
            >
            >
          • kjhseka
            Since I have only an username to access to the site, I suppose to have all the permissions to edit my own directoires. I have an hosting account, so art is
            Message 5 of 8 , Jun 1, 2005
            • 0 Attachment
              Since I have only an username to access to the site, I suppose to
              have all the permissions to edit my own directoires. I have an
              hosting account, so "art" is my username. Or perhaps the cron program
              is using another username? I don't think so.

              I will check the file opening with die function, and I will let you
              know.

              Alph

              --- In perl-beginner@yahoogroups.com, Brad Lhotsky <brad@d...> wrote:
              > It wouldn't hurt to check to ensure you opened the files.
              > ie:
              >
              > open (YDAY_CNT, "/home/art/public_html/lg/tod_cnt.dat")
              > or die "unable to open file: $!";
              >
              > Make sure the cron entry is running with a user that has
              permissions to
              > read and write to your directories :)
              >
              >
              > On Wed, Jun 01, 2005 at 08:40:14PM -0000, kjhseka wrote:
              > > Hello,
              > > I have a strange problem with a script that should be executed by
              a
              > > cronjob. The script would count the number of visits a website
              > > receives daily. For this, it use two files and do the following:
              > >
              > > 1) read the yesterday counter value stored in the file tod_cnt.dat
              > > 2) read the file counter.dat, the today counter value
              > > 3) substract yesterday value from today value
              > >
              > > If I execute the script in the server with these commands:
              > >
              > > cd public_html
              > > cd cgi-bin
              > > perl puthit.pl
              > >
              > > The script work properly.
              > >
              > > But if I run the cron job with the command
              > >
              > > perl /home/art/public_html/cgi-bin/puthit.pl
              > >
              > > The script generated a set of warnings and give incorrect
              results, 0
              > > instead of the number of visits. Why?
              > >
              > > Here's the script:
              > >
              > > #!/usr/bin/perl -w
              > >
              > > use strict;
              > >
              > > print "Content-type: text/plain", "\n\n";
              > >
              > > my ($yday_cnt, # yesterday hits
              > > $tday_cnt, # today hits
              > > $nbvisits); # daily visits
              > >
              > > open (YDAY_CNT, "/home/art/public_html/lg/tod_cnt.dat");
              > > $yday_cnt = <YDAY_CNT>;
              > > close YDAY_CNT;
              > >
              > > open (CNT, "/home/art/public_html/cgi-bin/counter.dat");
              > > $tday_cnt = <CNT>;
              > > close CNT;
              > >
              > > $nbvisits = $tday_cnt - $yday_cnt;
              > >
              > > # Update the today total visits file
              > > open (TOT_CNT, ">/home/art/public_html/lg/tod_cnt.dat");
              > > print TOT_CNT $tday_cnt;
              > > close TOT_CNT;
              > >
              > > open (TDAY_VISITS, ">/home/art/public_html/lg/tdhits.dat");
              > > print TDAY_VISITS $nbvisits;
              > > close TDAY_VISITS;
              > >
              > > # Generate output in case of online consultation
              > > print "<html><head><title>Output generated by puthit.pl, the
              > > automated visit counter</head></title>";
              > > print "<body>$tday_cnt<br>$nbvisits<br></body></html>";
              > >
              > > exit(0);
              > >
              > >
              > > The warnings are:
              > > readline() on closed filehandle YDAY_CNT at home/art....., line 12
              > > readline() on closed filehandle CNT at home/art....., line 16
              > > use of uninitialized value in subtraction (0) at home/art...,
              line 19
              > > idem
              > > print() on closed filehandle TOT_CNT at /home/art.... line 23
              > > print() on closed filehandle TDAY_VISITS at /home/art.... line 27
              > > Use of uninitialized value in concatenation (.) or string
              > > at /home/art..... line 32
              > >
              > >
              > > The output give incorrect results.
              > >
              > > I don't understand these warning and I don't understant why the
              > > script doesn't work when I execute it via a cron job.
              > >
              > > Can you give me any help?
              > >
              > > Thanks
              > > Alph
              > >
              > >
              > >
              > >
              > >
              > > Unsubscribing info is here:
              http://help.yahoo.com/help/us/groups/groups-32.html
              > > Yahoo! Groups Links
              > >
              > >
              > >
              > >
              > >
              > >
              > >
              >
              > --
              > Brad Lhotsky <brad@d...>
            • kjhseka
              I forget something... Even if I run the script from the comand line as perl /home/art/public_html/cgi-bin/puthit.pl I get the same strange results! Only if I
              Message 6 of 8 , Jun 1, 2005
              • 0 Attachment
                I forget something... Even if I run the script from the comand line
                as

                perl /home/art/public_html/cgi-bin/puthit.pl

                I get the same strange results! Only if I cd until cgi-bin directory
                and only inside thit directory the script run properly and I get the
                results I expect.

                Alph

                --- In perl-beginner@yahoogroups.com, "Kris Stitt" <kris@a...> wrote:
                > I don't have a full answer for this but I might have a clue or
                two. I think
                > that cron does not have all of the same settings that a normal user
                would
                > have. So some of you enviromental veriables may not be understood
                in a cron
                > job (pathing etc.)
                >
                > I've been calling perl sripts from cron using a shell file, this
                seems to
                > work for me:
                > 00 6-19 * * 1-5 /usr/local/bin/monthly.sh
                >
                > Inside the monthly.sh file is actually the command to run the perl
                script:
                >
                > perl /user/local/bin/monthly.pl
                >
                > I'm not sure if any of that makes sense or not. (There is probably
                a much
                > better way to do this.)
                >
                >
                >
                > Good Luck,
                >
                > -Kris
                >
                >
                > ----- Original Message -----
                > From: "kjhseka" <kjhseka@h...>
                > To: <perl-beginner@yahoogroups.com>
                > Sent: Wednesday, June 01, 2005 1:40 PM
                > Subject: [PBML] Strange issue with cronjobs
                >
                >
                > > Hello,
                > > I have a strange problem with a script that should be executed by
                a
                > > cronjob. The script would count the number of visits a website
                > > receives daily. For this, it use two files and do the following:
                > >
                > > 1) read the yesterday counter value stored in the file tod_cnt.dat
                > > 2) read the file counter.dat, the today counter value
                > > 3) substract yesterday value from today value
                > >
                > > If I execute the script in the server with these commands:
                > >
                > > cd public_html
                > > cd cgi-bin
                > > perl puthit.pl
                > >
                > > The script work properly.
                > >
                > > But if I run the cron job with the command
                > >
                > > perl /home/art/public_html/cgi-bin/puthit.pl
                > >
                > > The script generated a set of warnings and give incorrect
                results, 0
                > > instead of the number of visits. Why?
                > >
                > > Here's the script:
                > >
                > > #!/usr/bin/perl -w
                > >
                > > use strict;
                > >
                > > print "Content-type: text/plain", "\n\n";
                > >
                > > my ($yday_cnt, # yesterday hits
                > > $tday_cnt, # today hits
                > > $nbvisits); # daily visits
                > >
                > > open (YDAY_CNT, "/home/art/public_html/lg/tod_cnt.dat");
                > > $yday_cnt = <YDAY_CNT>;
                > > close YDAY_CNT;
                > >
                > > open (CNT, "/home/art/public_html/cgi-bin/counter.dat");
                > > $tday_cnt = <CNT>;
                > > close CNT;
                > >
                > > $nbvisits = $tday_cnt - $yday_cnt;
                > >
                > > # Update the today total visits file
                > > open (TOT_CNT, ">/home/art/public_html/lg/tod_cnt.dat");
                > > print TOT_CNT $tday_cnt;
                > > close TOT_CNT;
                > >
                > > open (TDAY_VISITS, ">/home/art/public_html/lg/tdhits.dat");
                > > print TDAY_VISITS $nbvisits;
                > > close TDAY_VISITS;
                > >
                > > # Generate output in case of online consultation
                > > print "<html><head><title>Output generated by puthit.pl, the
                > > automated visit counter</head></title>";
                > > print "<body>$tday_cnt<br>$nbvisits<br></body></html>";
                > >
                > > exit(0);
                > >
                > >
                > > The warnings are:
                > > readline() on closed filehandle YDAY_CNT at home/art....., line 12
                > > readline() on closed filehandle CNT at home/art....., line 16
                > > use of uninitialized value in subtraction (0) at home/art...,
                line 19
                > > idem
                > > print() on closed filehandle TOT_CNT at /home/art.... line 23
                > > print() on closed filehandle TDAY_VISITS at /home/art.... line 27
                > > Use of uninitialized value in concatenation (.) or string
                > > at /home/art..... line 32
                > >
                > >
                > > The output give incorrect results.
                > >
                > > I don't understand these warning and I don't understant why the
                > > script doesn't work when I execute it via a cron job.
                > >
                > > Can you give me any help?
                > >
                > > Thanks
                > > Alph
                > >
                > >
                > >
                > >
                > >
                > > Unsubscribing info is here:
                > > http://help.yahoo.com/help/us/groups/groups-32.html
                > > Yahoo! Groups Links
                > >
                > >
                > >
                > >
                > >
                > >
                > >
                > >
                > >
              • mail meda
                Hi, For the script to be execute as cronjob. 1. Check whether are you using user env variables in your program. Load them at the start of the crontab file.
                Message 7 of 8 , Jun 2, 2005
                • 0 Attachment
                  Hi,

                  For the script to be execute as cronjob.

                  1. Check whether are you using user env variables in your program.
                  Load them at the start of the crontab file.
                  Check for the shell which you are using.
                  You can say SHELL=/bin/sh like.
                  2. For IO handles Try with IO::Handle and IO::File module.
                  3. Make the file as executable. chmod +x filename.
                  4. use exception handling while opening the files.This may throw any errors
                  if it has.
                  open ( FH,"/home/..") or die "Could not open file";
                  5. Check for the ownership and permissions of the file which you are using.

                  Regards,
                  Shiva.





                  On 6/2/05, kjhseka <kjhseka@...> wrote:
                  >
                  > I forget something... Even if I run the script from the comand line
                  > as
                  >
                  > perl /home/art/public_html/cgi-bin/puthit.pl
                  >
                  > I get the same strange results! Only if I cd until cgi-bin directory
                  > and only inside thit directory the script run properly and I get the
                  > results I expect.
                  >
                  > Alph
                  >
                  > --- In perl-beginner@yahoogroups.com, "Kris Stitt" <kris@a...> wrote:
                  > > I don't have a full answer for this but I might have a clue or
                  > two. I think
                  > > that cron does not have all of the same settings that a normal user
                  > would
                  > > have. So some of you enviromental veriables may not be understood
                  > in a cron
                  > > job (pathing etc.)
                  > >
                  > > I've been calling perl sripts from cron using a shell file, this
                  > seems to
                  > > work for me:
                  > > 00 6-19 * * 1-5 /usr/local/bin/monthly.sh
                  > >
                  > > Inside the monthly.sh file is actually the command to run the perl
                  > script:
                  > >
                  > > perl /user/local/bin/monthly.pl
                  > >
                  > > I'm not sure if any of that makes sense or not. (There is probably
                  > a much
                  > > better way to do this.)
                  > >
                  > >
                  > >
                  > > Good Luck,
                  > >
                  > > -Kris
                  > >
                  > >
                  > > ----- Original Message -----
                  > > From: "kjhseka" <kjhseka@h...>
                  > > To: <perl-beginner@yahoogroups.com>
                  > > Sent: Wednesday, June 01, 2005 1:40 PM
                  > > Subject: [PBML] Strange issue with cronjobs
                  > >
                  > >
                  > > > Hello,
                  > > > I have a strange problem with a script that should be executed by
                  > a
                  > > > cronjob. The script would count the number of visits a website
                  > > > receives daily. For this, it use two files and do the following:
                  > > >
                  > > > 1) read the yesterday counter value stored in the file tod_cnt.dat
                  > > > 2) read the file counter.dat, the today counter value
                  > > > 3) substract yesterday value from today value
                  > > >
                  > > > If I execute the script in the server with these commands:
                  > > >
                  > > > cd public_html
                  > > > cd cgi-bin
                  > > > perl puthit.pl
                  > > >
                  > > > The script work properly.
                  > > >
                  > > > But if I run the cron job with the command
                  > > >
                  > > > perl /home/art/public_html/cgi-bin/puthit.pl
                  > > >
                  > > > The script generated a set of warnings and give incorrect
                  > results, 0
                  > > > instead of the number of visits. Why?
                  > > >
                  > > > Here's the script:
                  > > >
                  > > > #!/usr/bin/perl -w
                  > > >
                  > > > use strict;
                  > > >
                  > > > print "Content-type: text/plain", "\n\n";
                  > > >
                  > > > my ($yday_cnt, # yesterday hits
                  > > > $tday_cnt, # today hits
                  > > > $nbvisits); # daily visits
                  > > >
                  > > > open (YDAY_CNT, "/home/art/public_html/lg/tod_cnt.dat");
                  > > > $yday_cnt = <YDAY_CNT>;
                  > > > close YDAY_CNT;
                  > > >
                  > > > open (CNT, "/home/art/public_html/cgi-bin/counter.dat");
                  > > > $tday_cnt = <CNT>;
                  > > > close CNT;
                  > > >
                  > > > $nbvisits = $tday_cnt - $yday_cnt;
                  > > >
                  > > > # Update the today total visits file
                  > > > open (TOT_CNT, ">/home/art/public_html/lg/tod_cnt.dat");
                  > > > print TOT_CNT $tday_cnt;
                  > > > close TOT_CNT;
                  > > >
                  > > > open (TDAY_VISITS, ">/home/art/public_html/lg/tdhits.dat");
                  > > > print TDAY_VISITS $nbvisits;
                  > > > close TDAY_VISITS;
                  > > >
                  > > > # Generate output in case of online consultation
                  > > > print "<html><head><title>Output generated by puthit.pl, the
                  > > > automated visit counter</head></title>";
                  > > > print "<body>$tday_cnt<br>$nbvisits<br></body></html>";
                  > > >
                  > > > exit(0);
                  > > >
                  > > >
                  > > > The warnings are:
                  > > > readline() on closed filehandle YDAY_CNT at home/art....., line 12
                  > > > readline() on closed filehandle CNT at home/art....., line 16
                  > > > use of uninitialized value in subtraction (0) at home/art...,
                  > line 19
                  > > > idem
                  > > > print() on closed filehandle TOT_CNT at /home/art.... line 23
                  > > > print() on closed filehandle TDAY_VISITS at /home/art.... line 27
                  > > > Use of uninitialized value in concatenation (.) or string
                  > > > at /home/art..... line 32
                  > > >
                  > > >
                  > > > The output give incorrect results.
                  > > >
                  > > > I don't understand these warning and I don't understant why the
                  > > > script doesn't work when I execute it via a cron job.
                  > > >
                  > > > Can you give me any help?
                  > > >
                  > > > Thanks
                  > > > Alph
                  > > >
                  > > >
                  > > >
                  > > >
                  > > >
                  > > > Unsubscribing info is here:
                  > > > http://help.yahoo.com/help/us/groups/groups-32.html
                  > > > Yahoo! Groups Links
                  > > >
                  > > >
                  > > >
                  > > >
                  > > >
                  > > >
                  > > >
                  > > >
                  > > >
                  >
                  >
                  >
                  >
                  >
                  > Unsubscribing info is here:
                  > http://help.yahoo.com/help/us/groups/groups-32.html
                  > Yahoo! Groups Links
                  >
                  >
                  >
                  >
                  >
                  >
                  >


                  [Non-text portions of this message have been removed]
                • kjhseka
                  Hello, I checked permissions of the files and add die function, and now problem is solved. Thanks you all Alph ... permissions to ... a ... results, 0 ... line
                  Message 8 of 8 , Jun 2, 2005
                  • 0 Attachment
                    Hello,
                    I checked permissions of the files and add die function, and now
                    problem is solved.

                    Thanks you all
                    Alph

                    --- In perl-beginner@yahoogroups.com, Brad Lhotsky <brad@d...> wrote:
                    > It wouldn't hurt to check to ensure you opened the files.
                    > ie:
                    >
                    > open (YDAY_CNT, "/home/art/public_html/lg/tod_cnt.dat")
                    > or die "unable to open file: $!";
                    >
                    > Make sure the cron entry is running with a user that has
                    permissions to
                    > read and write to your directories :)
                    >
                    >
                    > On Wed, Jun 01, 2005 at 08:40:14PM -0000, kjhseka wrote:
                    > > Hello,
                    > > I have a strange problem with a script that should be executed by
                    a
                    > > cronjob. The script would count the number of visits a website
                    > > receives daily. For this, it use two files and do the following:
                    > >
                    > > 1) read the yesterday counter value stored in the file tod_cnt.dat
                    > > 2) read the file counter.dat, the today counter value
                    > > 3) substract yesterday value from today value
                    > >
                    > > If I execute the script in the server with these commands:
                    > >
                    > > cd public_html
                    > > cd cgi-bin
                    > > perl puthit.pl
                    > >
                    > > The script work properly.
                    > >
                    > > But if I run the cron job with the command
                    > >
                    > > perl /home/art/public_html/cgi-bin/puthit.pl
                    > >
                    > > The script generated a set of warnings and give incorrect
                    results, 0
                    > > instead of the number of visits. Why?
                    > >
                    > > Here's the script:
                    > >
                    > > #!/usr/bin/perl -w
                    > >
                    > > use strict;
                    > >
                    > > print "Content-type: text/plain", "\n\n";
                    > >
                    > > my ($yday_cnt, # yesterday hits
                    > > $tday_cnt, # today hits
                    > > $nbvisits); # daily visits
                    > >
                    > > open (YDAY_CNT, "/home/art/public_html/lg/tod_cnt.dat");
                    > > $yday_cnt = <YDAY_CNT>;
                    > > close YDAY_CNT;
                    > >
                    > > open (CNT, "/home/art/public_html/cgi-bin/counter.dat");
                    > > $tday_cnt = <CNT>;
                    > > close CNT;
                    > >
                    > > $nbvisits = $tday_cnt - $yday_cnt;
                    > >
                    > > # Update the today total visits file
                    > > open (TOT_CNT, ">/home/art/public_html/lg/tod_cnt.dat");
                    > > print TOT_CNT $tday_cnt;
                    > > close TOT_CNT;
                    > >
                    > > open (TDAY_VISITS, ">/home/art/public_html/lg/tdhits.dat");
                    > > print TDAY_VISITS $nbvisits;
                    > > close TDAY_VISITS;
                    > >
                    > > # Generate output in case of online consultation
                    > > print "<html><head><title>Output generated by puthit.pl, the
                    > > automated visit counter</head></title>";
                    > > print "<body>$tday_cnt<br>$nbvisits<br></body></html>";
                    > >
                    > > exit(0);
                    > >
                    > >
                    > > The warnings are:
                    > > readline() on closed filehandle YDAY_CNT at home/art....., line 12
                    > > readline() on closed filehandle CNT at home/art....., line 16
                    > > use of uninitialized value in subtraction (0) at home/art...,
                    line 19
                    > > idem
                    > > print() on closed filehandle TOT_CNT at /home/art.... line 23
                    > > print() on closed filehandle TDAY_VISITS at /home/art.... line 27
                    > > Use of uninitialized value in concatenation (.) or string
                    > > at /home/art..... line 32
                    > >
                    > >
                    > > The output give incorrect results.
                    > >
                    > > I don't understand these warning and I don't understant why the
                    > > script doesn't work when I execute it via a cron job.
                    > >
                    > > Can you give me any help?
                    > >
                    > > Thanks
                    > > Alph
                    > >
                    > >
                    > >
                    > >
                    > >
                    > > Unsubscribing info is here:
                    http://help.yahoo.com/help/us/groups/groups-32.html
                    > > Yahoo! Groups Links
                    > >
                    > >
                    > >
                    > >
                    > >
                    > >
                    > >
                    >
                    > --
                    > Brad Lhotsky <brad@d...>
                  Your message has been successfully submitted and would be delivered to recipients shortly.