I try to catch and save in a log file the output of LFTP using unbuffer, because seems impossible to get it via other ways, namely the usual > logfile.txt

Certainly the format shown in the shell is what I prefer because other dialogs (like using --log= or
xfer:log-file) don't show the information about the progress so good as is shown in the shell.

Let me show you all the line I'm using ...

unbuffer lftp -e "set ssl:verify-certificate no; set ftp:ssl-protect-data yes; set ftp:ssl-protect-list yes; mirror --reverse /path/to/send folder_to_receive_files ; quit" -u user@server.com,password ftp.server.com > mylog.log 2>&1

In the shell (I'm using Ubuntu) and using unbuffer I get the output well ...

mkdir `folder_to_receive_files' [Connecting...]
mkdir `folder_to_receive_files' [Waiting for response...]

Transferring file `OctoCod_1920x1080_Hitman.hevc.good.mp4'
`OctoCod_1920x1080_Hitman.hevc.good.mp4' at 0 (0%) [Waiting for response...]
`OctoCod_1920x1080_Hitman.hevc.good.mp4' at 76744 (0%) [Sending data]
`OctoCod_1920x1080_Hitman.hevc.good.mp4' at 608160 (2%) 397.4K/s eta:58s [Sending data]
.. etc ...

BUT this is the problem!! ...

Passing above set of LFTP commands through PHP exec, namely exec('unbuffer lftp -e "set ssl:verify-certificate no; set... etc, etc);

I cannot get the right dialog, but I get a cut version of the full dialog, like that ...

mkdir `folder_to_receive_files' [Connecting...]
mkdir `folder_to_receive_files' [Waiting for response...]
`...d_1920x1080_Hitman.hevc.mp4' at 0 (0%) [Waiting for response...]
`...d_1920x1080_Hitman.hevc.mp4' at 125976 (0%) [Sending data]
`...d_1920x1080_Hitman.hevc.mp4' at 660288 (2%) 431.4K/s eta:63s [Sending data]
`...d_1920x1080_Hitman.hevc.mp4' at 1211976 (4%) 492.7K/s eta:54s [Sending data
`...d_1920x1080_Hitman.hevc.mp4' at 1785384 (6%) 579.6K/s eta:45s [Sending data
`...d_1920x1080_Hitman.hevc.mp4' at 2358792 (8%) 607.8K/s eta:42s [Sending data
`...d_1920x1080_Hitman.hevc.mp4' at 2932200 (10%) 619.6K/s eta:40s [Sending dat
`...d_1920x1080_Hitman.hevc.mp4' at 3505608 (12%) 639.3K/s eta:38s [Sending dat
`...d_1920x1080_Hitman.hevc.mp4' at 4079016 (14%) 634.0K/s eta:38s [Sending dat

It's something strange and is making me crazy. I have been two full days fighting against this problem.

Anyone has some idea about what is happening?

Thank you very much in advance for your help.

    maybe try using shell_exec(), instead, and let it return whatever gets output to a variable?

      NogDog;11045807 wrote:

      maybe try using shell_exec(), instead, and let it return whatever gets output to a variable?

      I used the other parameters of exec, and what you said, namely to pass the output from shell_exec to a variable and I cannot capture anything, seems that LFTP doesn't send to stdout and because of this, people has to use unbuffer from expect-dev packet (you know: apt-get install expect-dev).

      Seems like exec is cutting up the strings. :-(

        You could try redirecting the command to a file and read that... command &> /tmp/temp_file_for_output or send the stderr to stdout using 2>&1

          Derokorian;11045823 wrote:

          You could try redirecting the command to a file and read that... command &> /tmp/temp_file_for_output or send the stderr to stdout using 2>&1

          Hi Derokorian,

          I already sent the stderr to stdout using 2>&1 and it doesn't work.

          But what you mentioned first sounds interesting. What do you mean about to redirecting the command to a file and read it later with &> file_with_command_saved.txt ??

          Currently the code is ...

          $command = 'unbuffer lftp -e etc, etc';
          exec($command);

          Some idea?

          Thank you very much in advance.
          Mapg

            Hmm sorry I missed that you tried it already. Didn't read close enough. I apologize as I have no experience with unbuffer or lftp so I'm not sure why any of these options wouldn't work from a standard bash perspective.

              Perhaps using [man]popen[/man] and reading from the resulting stream will work?

              mapg wrote:

              Some idea?

              I think what Derokorian means is redirecting stderr to a file, i.e., [font=monospace]2>mylog.log[/font].

                Write a Reply...