Can anyone tell me why this doesnt work please

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • nigel.t@by.uk

    Can anyone tell me why this doesnt work please


    Using linux

    <?php
    exec("/bin/tar -cvzf myfile.tgz /home/",$arrayout,$re turnval);
    ?>

    or perhaps try it on your system and tell me if it does/doesnt and what
    your linux is?

    I've also tried

    <?php
    exec("/bin/tar -c * \| gzip \myfile.tgz",$a rrayout,$return val);
    ?>

    Both work fine from the command line neither work at all from PHP

    -nigel-
  • Jerry Stuckle

    #2
    Re: Can anyone tell me why this doesnt work please

    nigel.t@by.uk wrote:
    Using linux
    >
    <?php
    exec("/bin/tar -cvzf myfile.tgz /home/",$arrayout,$re turnval);
    ?>
    >
    or perhaps try it on your system and tell me if it does/doesnt and what
    your linux is?
    >
    I've also tried
    >
    <?php
    exec("/bin/tar -c * \| gzip \myfile.tgz",$a rrayout,$return val);
    ?>
    >
    Both work fine from the command line neither work at all from PHP
    >
    -nigel-
    What kind of error do you get?

    --
    =============== ===
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    jstucklex@attgl obal.net
    =============== ===

    Comment

    • nigel.t@by.uk

      #3
      Re: Can anyone tell me why this doesnt work please

      In article <BNudneEBxth0dm PZnZ2dnUVZ_rmdn Z2d@comcast.com >,
      jstucklex@attgl obal.net says...
      nigel.t@by.uk wrote:
      Using linux

      <?php
      exec("/bin/tar -cvzf myfile.tgz /home/",$arrayout,$re turnval);
      ?>

      or perhaps try it on your system and tell me if it does/doesnt and what
      your linux is?

      I've also tried

      <?php
      exec("/bin/tar -c * \| gzip \myfile.tgz",$a rrayout,$return val);
      ?>

      Both work fine from the command line neither work at all from PHP

      -nigel-
      >
      What kind of error do you get?
      >
      --
      Hi Jerry - $returnval contains '2' in each case.
      $arrayout never seems to contain anything.

      I can however do -
      tar --help
      which does return the help.

      I've also tried to archive a single file with the same result
      ie. tar -cf myfile.tar foo
      returns an error of 2

      and i've tried the --ignore-failed-read flag to no avail.

      -nigel-

      Comment

      • Jerry Stuckle

        #4
        Re: Can anyone tell me why this doesnt work please

        nigel.t@by.uk wrote:
        In article <BNudneEBxth0dm PZnZ2dnUVZ_rmdn Z2d@comcast.com >,
        jstucklex@attgl obal.net says...
        >
        >>nigel.t@by. uk wrote:
        >>
        >>>Using linux
        >>>
        >>><?php
        >>>exec("/bin/tar -cvzf myfile.tgz /home/",$arrayout,$re turnval);
        >>>?>
        >>>
        >>>or perhaps try it on your system and tell me if it does/doesnt and what
        >>>your linux is?
        >>>
        >>>I've also tried
        >>>
        >>><?php
        >> exec("/bin/tar -c * \| gzip \myfile.tgz",$a rrayout,$return val);
        >>>?>
        >>>
        >>>Both work fine from the command line neither work at all from PHP
        >>>
        >>>-nigel-
        >>
        >>What kind of error do you get?
        >>
        >>--
        >
        >
        Hi Jerry - $returnval contains '2' in each case.
        $arrayout never seems to contain anything.
        >
        I can however do -
        tar --help
        which does return the help.
        >
        I've also tried to archive a single file with the same result
        ie. tar -cf myfile.tar foo
        returns an error of 2
        >
        and i've tried the --ignore-failed-read flag to no avail.
        >
        -nigel-
        Nigel,

        Does the cron job user have write access to the directory where you're
        writing myfile.tar? And does it have read access to /home?

        --
        =============== ===
        Remove the "x" from my email address
        Jerry Stuckle
        JDS Computer Training Corp.
        jstucklex@attgl obal.net
        =============== ===

        Comment

        • Andy Hassall

          #5
          Re: Can anyone tell me why this doesnt work please

          On Wed, 06 Sep 2006 16:37:35 GMT, nigel.t@by.uk wrote:
          >In article <BNudneEBxth0dm PZnZ2dnUVZ_rmdn Z2d@comcast.com >,
          >jstucklex@attg lobal.net says...
          >nigel.t@by.uk wrote:
          Using linux
          >
          <?php
          exec("/bin/tar -cvzf myfile.tgz /home/",$arrayout,$re turnval);
          ?>
          <?php
          exec("/bin/tar -c * \| gzip \myfile.tgz",$a rrayout,$return val);
          ?>
          >
          Both work fine from the command line neither work at all from PHP
          >>
          >What kind of error do you get?
          >
          >Hi Jerry - $returnval contains '2' in each case.
          >$arrayout never seems to contain anything.
          >
          >I can however do -
          >tar --help
          >which does return the help.
          >
          >I've also tried to archive a single file with the same result
          >ie. tar -cf myfile.tar foo
          >returns an error of 2
          >
          >and i've tried the --ignore-failed-read flag to no avail.
          errno 2 is "No such file or directory" - so I'm not quite sure what to make of
          that; permission denied would seem more likely.

          --
          Andy Hassall :: andy@andyh.co.u k :: http://www.andyh.co.uk
          http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

          Comment

          • Chris Parker

            #6
            Re: Can anyone tell me why this doesnt work please


            nigel.t@by.uk wrote:
            Using linux
            >
            <?php
            exec("/bin/tar -cvzf myfile.tgz /home/",$arrayout,$re turnval);
            ?>
            >
            or perhaps try it on your system and tell me if it does/doesnt and what
            your linux is?
            >
            I've also tried
            >
            <?php
            exec("/bin/tar -c * \| gzip \myfile.tgz",$a rrayout,$return val);
            ?>
            >
            Both work fine from the command line neither work at all from PHP
            >
            -nigel-
            Append this:

            for ($i = 0; $i < count($arrayout ); $i++) {
            echo $arrayout[$i] . "\n";

            }

            and see what the command output is.

            Chris

            Comment

            • nigel.t@by.uk

              #7
              Re: Can anyone tell me why this doesnt work please

              In article <1157580853.031 347.172630@i42g 2000cwa.googleg roups.com>,
              mrcsparker@gmai l.com says...
              >
              nigel.t@by.uk wrote:
              Using linux

              <?php
              exec("/bin/tar -cvzf myfile.tgz /home/",$arrayout,$re turnval);
              ?>

              or perhaps try it on your system and tell me if it does/doesnt and what
              your linux is?

              I've also tried

              <?php
              exec("/bin/tar -c * \| gzip \myfile.tgz",$a rrayout,$return val);
              ?>

              Both work fine from the command line neither work at all from PHP

              -nigel-
              >
              Append this:
              >
              for ($i = 0; $i < count($arrayout ); $i++) {
              echo $arrayout[$i] . "\n";
              >
              }
              >
              and see what the command output is.
              >
              Chris
              >
              >
              Thanks Chris but I already have this which is how I know the array is
              empty. I'm getting more confused by the minute.

              -nigel-

              Comment

              • nigel.t@by.uk

                #8
                Re: Can anyone tell me why this doesnt work please

                In article <NJGdnWxbnZ2diG LZnZ2dnUVZ_q-dnZ2d@comcast.c om>,
                jstucklex@attgl obal.net says...
                >
                Nigel,
                >
                Does the cron job user have write access to the directory where you're
                writing myfile.tar? And does it have read access to /home?
                >
                >
                Hi Jerry

                Sadly I'm not a Linux expert - I know what persmissions are but I dont
                know what a "cron job" is.
                I'm guessing you mean the apache server?

                /home is the directory the php file is in as well as the test file to be
                archived and is set to 777 for directory and all files - I panicked when
                I first couldnt make it work! I assume that means it has full read/write.

                I have so far assumed all permissions are granted as the machine is my
                test machine not networked to anything and I have everything I can find
                set to 777 to avoid this ... I seem to remember running chmod 777 from
                the root and recursing... I then manually change back my final test
                files/dirs to 755 and so on... ie the reverse procedure used on a public
                system.

                I also log on as root. (I have tried another user account and that
                performs the same).

                I can see where you are going and you may well be right - I just dont
                know what to look for ... how can I identify the less obvious things I
                need to check for permissions? (I can do file & directories its perhaps
                that cron job etc.)

                -nigel-

                Comment

                • nigel.t@by.uk

                  #9
                  Re: Can anyone tell me why this doesnt work please

                  In article <03duf2lu9v47h7 tltmbvtdsgd7gjn a8oge@4ax.com>, andy@andyh.co.u k
                  says
                  Hi Jerry - $returnval contains '2' in each case.
                  $arrayout never seems to contain anything.

                  I can however do -
                  tar --help
                  which does return the help.

                  I've also tried to archive a single file with the same result
                  ie. tar -cf myfile.tar foo
                  returns an error of 2

                  and i've tried the --ignore-failed-read flag to no avail.
                  >
                  errno 2 is "No such file or directory" - so I'm not quite sure what to make of
                  that; permission denied would seem more likely.
                  >
                  Thanks for the info Andy.
                  Can you tell me where that is documented - I can't find it.

                  I don't get this - the same error 2 occurs even if I use * or *.* or just
                  a directory name. The tar manual suggests those are all valid so I dont
                  know how it can think the file isnt there... stwange .....vewy stwange...

                  This is bound to be a permissions thing somehow ... you're both right I
                  expect... I just can't find the blockage.

                  -nigel-

                  Comment

                  • Petr Vileta

                    #10
                    Re: Can anyone tell me why this doesnt work please

                    <nigel.t@by.ukw rote in
                    news:MPG.1f68e3 133d5c070c9898f e@news-text.blueyonder .co.uk...
                    >
                    Using linux
                    >
                    <?php
                    exec("/bin/tar -cvzf myfile.tgz /home/",$arrayout,$re turnval);
                    ?>
                    >
                    Try to use singe quote instead the double quote. I'm no sure if this is the
                    same in PHP as is in Perl but in Perl double quote evaluate something but
                    single quote don't.
                    Example in Perl:

                    $name = "nigel";
                    print "Hallo $name";
                    >Hallo nigel
                    $name = "nigel";
                    print 'Hallo $name';
                    >Hallo $name
                    Maybe is some similar in PHP.

                    --

                    Petr Vileta, Czech republic
                    (My server rejects all messages from Yahoo and Hotmail. Send me your mail
                    from another non-spammer site please.)


                    Comment

                    • nigel.t@by.uk

                      #11
                      Re: Can anyone tell me why this doesnt work please

                      In article <ednpik$eeb$1@n s.felk.cvut.cz> , stoupa@practiso ft.cz says...
                      <
                      Try to use singe quote instead the double quote. I'm no sure if this is the
                      same in PHP as is in Perl but in Perl double quote evaluate something but
                      single quote don't.
                      Example in Perl:
                      >
                      $name = "nigel";
                      print "Hallo $name";
                      Hallo nigel
                      >
                      $name = "nigel";
                      print 'Hallo $name';
                      Hallo $name
                      >
                      Maybe is some similar in PHP.
                      >
                      --
                      >
                      Petr Vileta, Czech republic
                      (My server rejects all messages from Yahoo and Hotmail. Send me your mail
                      from another non-spammer site please.)
                      >
                      >
                      >
                      Thanks Petr - yes the quotes are different in PHP too... doubles allow
                      more escaped characters.

                      Turns out that wasn't it though - see my next post !

                      -nigel-

                      Comment

                      • nigel.t@by.uk

                        #12
                        Re: Can anyone tell me why this doesnt work please - GOT IT !!!


                        damn and blast ... colour me stupid and spank my soft extremeties...

                        It was those last explanations that set me thinking...
                        It had to be permissions because it works ok on the command line so...
                        I ran my chmod -R / again... (not recommended on a live system folks!)

                        It turns out the directory the .tar file is created in must have 777
                        permissions ... 775 wont do it... it must have that extra bit set.

                        (I dont understand why at all - I can exec other apps that write to files
                        without any trouble at all... I REALLY would like an explanation if
                        anyone has one, bearing that fact in mind)

                        It generates a file not found because it's looking for the tar file and
                        hasn't created it (possibly error reporting could be tightened up to be
                        more accurate in Tar) ...

                        Anyways -- many thanks to all who followed me on my wild goose chase.
                        All I have to do now is see if I can make it work on the live system...

                        Oh boy oh boy.... aint pc's fun. I can even go to bed tonight.

                        -nigel-

                        Comment

                        • Petr Vileta

                          #13
                          Re: Can anyone tell me why this doesnt work please - GOT IT !!!

                          <nigel.t@by.ukw rote in
                          news:MPG.1f6983 e17848cc4798990 4@news-text.blueyonder .co.uk...
                          >
                          It turns out the directory the .tar file is created in must have 777
                          permissions ... 775 wont do it... it must have that extra bit set.
                          >
                          I'm not a Linux guru but maybe can help you to use some tar parameter. Try
                          to tell to tar thaht the temporary file must be created in /tmp dir. This
                          directory used to have 777 privileges at all. Or try to create tar file in
                          /tmp directory and after creating copy tar file to desired destination.
                          --

                          Petr Vileta, Czech republic
                          (My server rejects all messages from Yahoo and Hotmail. Send me your mail
                          from another non-spammer site please.)


                          Comment

                          • nigel.t@by.uk

                            #14
                            Re: Can anyone tell me why this doesnt work please - GOT IT !!!

                            In article <edp72e$156v$3@ ns.felk.cvut.cz >, stoupa@practiso ft.cz says...
                            <nigel.t@by.ukw rote in
                            news:MPG.1f6983 e17848cc4798990 4@news-text.blueyonder .co.uk...

                            It turns out the directory the .tar file is created in must have 777
                            permissions ... 775 wont do it... it must have that extra bit set.
                            I'm not a Linux guru but maybe can help you to use some tar parameter. Try
                            to tell to tar thaht the temporary file must be created in /tmp dir. This
                            directory used to have 777 privileges at all. Or try to create tar file in
                            /tmp directory and after creating copy tar file to desired destination.
                            --
                            >
                            Petr Vileta, Czech republic
                            (My server rejects all messages from Yahoo and Hotmail. Send me your mail
                            from another non-spammer site please.)
                            >
                            >
                            >
                            Thanks Petr thats pretty much what I did.
                            Its still a puzzle I need to understand but at least I can get it working
                            now. I just hope I dont run into problems using chmod with PHP
                            through apache or that will screw me up.

                            -nigel-

                            Comment

                            Working...