From: Murray R. Van Luyn. on

"Sidney Lambe" <sidneylambe(a)nospam.invalid> wrote in message
news:slrnhjrnr0.pga.sidneylambe(a)evergreen.net...
> On comp.unix.shell, Murray R. Van Luyn. <valid(a)email.address>
> wrote:
>
>> "Murray R. Van Luyn." <valid(a)email.address> wrote in message
>> news:vsednRKwVb5_NqDWnZ2dnUVZ_umdnZ2d(a)westnet.com.au...
>>
>>> "mop2" <invalid(a)mail.address> wrote in message
>>> news:op.u5tpileof8ly3v(a)k7...
>>>
>>>> On Thu, 31 Dec 2009 19:30:10 -0200, Murray R. Van Luyn.
>>>> <valid(a)email.address> wrote:
>>>>
>>>>> Golly, I know next to nothing about Unix shell commands. I'm
>>>>> just trying to get a zipfile download preparation script in
>>>>> PHP to work on my website. The idea is just to touch the
>>>>> payload timestamps of my zipfile downloads, as a means of
>>>>> having then uniquely traceable to individual microcontroller
>>>>> software purchasers.
>>>>
>>>>
>>>>>> rezip(){ [ $1 ]&&[ -e $1]||return
>>>>>
>>>>> I'm fascinated by this snippet, mop2. What sort of language
>>>>> is that function written in? I may have to resort to
>>>>> some form of function loaded shell script for my command
>>>>> sequence, as I'm having trouble getting PHP's exec()
>>>>> function to run 'zip' consistently. It might be handy
>>>>> if I could fire-off a shell script with something like
>>>>> exec("rezip file.zip");
>>>>
>>>> That is a shell function Now what your need is more clear .
>>>>
>>>> Well, for dating your files, your case is more simple. Your
>>>> files can be stored in a private directory and a script touch
>>>> and zip them to a public directory, so:
>>>>
>>>> ####your script (for zipping) is just:
>>>>
>>>> touch /files/tozip/yourprg-1.0.0/*
>>>>
>>>> /usr/bin/zip < /files/tozip/yourprg-1.0.0
>>>>
>>>> >/your/download/area/yourprg-1.0.0.zip
>>>>
>>>> ######
>>>>
>>>> You only need control the condition of only one download per
>>>> time stamp.
>>>>
>>>> Your php interpreter can run a shell script (I think), as
>>>> above, or perhaps just:
>>>>
>>>> exec("line 1; line 2");
>>>>
>>>> Sorry, I don't know nothing about php.
>>>>
>>>
>>>
>>> Hi Mop2,
>>>
>>> Don't worry Mop2, I don't know nothing about PHP either.
>>> :-) The searchable documentation and examples are fabulous,
>>> however, and inspired cut & paste seems to get one a very long
>>> way.
>>>
>>> Hmm...what I really need is to write a tiny shell script
>>> that can iteratively work through a set of zip files,
>>> expanding, touching and re-compressing the contents of
>>> each. The idea would be to call it with a PHP command
>>> like exec("touchzipfilepayloads zipfile1.zip zipfile2.zip
>>> zipfile3.zip");
>>>
>>> I'll have to search for a simple shell script example that
>>> illustrates the control structure required to process a
>>> command line specified list of zip files. Once I have that, it
>>> will be a simple matter of substituting my unzip, touch, zip,
>>> rm command sequence.
>>>
>>> Gee, I hope the shell program 'zip' works a little better for
>>> me when called from a shell script. Otherwise, I'm no better
>>> off. Golly, isn't it a stimulating exercise, to battle through
>>> the maze of possible solutions and dead-ends, and finally
>>> arrive at working result? I'm having too much fun!
>>>
>>> Muz.
>>
>>
>
>> Does this look rational to anyone?
>>
>> #!/bin/sh
>>
>> while [ $# -ge 1 ]; do
>> unzip ./Secure/$1 -d ./Secure/Temp > /dev/null 2>&1
>> touch ./Secure/Temp/* > /dev/null 2>&1
>> zip -j ./Secure/$1 ./Secure/Temp/* > /dev/null 2>&1
>> rm ./Secure/Temp/* > /dev/null 2>&1
>> shift
>> done
>>
>> exit 0
>>
>>
>> Called with something like:
>>
>> ./touchzipfilepayloads zipfile1.zip zipfile2.zip zipfile3.zip
>>
>> Muz.
>>
>>
>
> Looks like it would probably work. I don't know zip very
> well.
>
> (How come you are using what is essentially a Windows tool?
> Why not tar?)
>
> (> /dev/null 2>&1 instead of that, I use &> /dev/null.)
>
> The thing to do is make some throwaway zip files and the
> necessary dirs and test it.
>
> Sid
>

Hi Sidney,

Yes, the code that I make available to customers is usually downloaded by
Windows users. I've always distributed zip files that I create with WinZip,
so I thought using the Unix zip command would give me the best compatibility
with those.

Okay, I've tried it out and am starting to get a handle on the problem. When
initiated with PHP's exec() function I couldn't get any textural feedback
from running the zip command. When I ran zip in a shell script I was able to
redirect the results of the execution attempt to a file for post-mortem
analysis. The output reads "./touchzipfilepayloads: line 6: zip: command not
found". I now have this important clue as to what's going wrong. Once in a
while the OS can find the zip executable, though most frequently it fails
to.

I'll see what my ISP has to say about the apparent, predominately
un-locatable zip executable. They're not known for their fabulous customer
service, so I fear this may be where the current avenue of exploration ends.

I'll try to let you all know what happens.

Muz.




From: Jon LaBadie on
Murray R. Van Luyn. wrote:
>
> Does this look rational to anyone?
>
> #!/bin/sh
>
> while [ $# -ge 1 ]; do
> unzip ./Secure/$1 -d ./Secure/Temp > /dev/null 2>&1
> touch ./Secure/Temp/* > /dev/null 2>&1
> zip -j ./Secure/$1 ./Secure/Temp/* > /dev/null 2>&1
> rm ./Secure/Temp/* > /dev/null 2>&1
> shift
> done
>
> exit 0
>
>
> Called with something like:
>
> ./touchzipfilepayloads zipfile1.zip zipfile2.zip zipfile3.zip
>
>

Any reason you don't cd into Secure?

Zip will create "Temp" if it doesn't exist, but the second
time you run touchzipfilepayloads it will exist. Consider
adding a check that you can rwx the Temp dir if it exists.

If there is a chance that the original zipfiles contained
subdirectories, should the final zip also use the -r option?

You probably should be quoting all instances of $1 just in case.

Throwing away all error messages?

Using the -j option will flatten all directory structure.
If the original zipfile contained "a" and "b/c", the final
zipfile will contain "a" and "c", no indication of directory "b".
Duplicate names in subdirs will be a possible problem.

Actually, as you reuse the zipfile, i.e. don't remove or rename it,
the final zipfile in my above example would probably contain an
updated "a", a new "c", and an unchanged "b/c".
From: Ben Bacarisse on
"Murray R. Van Luyn." <valid(a)email.address> writes:
<snip>
> ... I've always distributed zip files that I create with WinZip,
> so I thought using the Unix zip command would give me the best compatibility
> with those.
>
> Okay, I've tried it out and am starting to get a handle on the problem. When
> initiated with PHP's exec() function I couldn't get any textural feedback
> from running the zip command.
<snip>
> I'll see what my ISP has to say about the apparent, predominately
> un-locatable zip executable. They're not known for their fabulous customer
> service, so I fear this may be where the current avenue of
> exploration ends.

Does your PHP installation have the zip functions? It is not as
simple as a script, but it will get the job done if your hosting
company won't install a zip executable.

<snip>
--
Ben.
From: mop2 on
On Fri, 01 Jan 2010 11:30:01 -0200, Murray R. Van Luyn. <valid(a)email.address> wrote:

>>> "Murray R. Van Luyn." <valid(a)email.address> wrote in message

>>> #!/bin/sh
>>>
>>> while [ $# -ge 1 ]; do
>>> unzip ./Secure/$1 -d ./Secure/Temp > /dev/null 2>&1
>>> touch ./Secure/Temp/* > /dev/null 2>&1
>>> zip -j ./Secure/$1 ./Secure/Temp/* > /dev/null 2>&1
>>> rm ./Secure/Temp/* > /dev/null 2>&1
>>> shift
>>> done
>>>
>>> exit 0

> initiated with PHP's exec() function I couldn't get any textural feedback


You can try, in the while loop:

while

here
remove
the redirections

done >>./Secure/touchzipfilepayloads.log 2>&1

In your browser you open an other window to follow (and refresh the view) rezip.log
From: Bill Marcum on
On 2010-01-01, Murray R. Van Luyn. <valid(a)email.address> wrote:
>
> Okay, I've tried it out and am starting to get a handle on the problem. When
> initiated with PHP's exec() function I couldn't get any textural feedback
> from running the zip command. When I ran zip in a shell script I was able to
> redirect the results of the execution attempt to a file for post-mortem
> analysis. The output reads "./touchzipfilepayloads: line 6: zip: command not
> found". I now have this important clue as to what's going wrong. Once in a
> while the OS can find the zip executable, though most frequently it fails
> to.
>
What OS are you using? What does your ISP have to do with your OS? Is
it one of their servers you are using? The "command not found" error
could mean your PATH is wrong, or possibly zip requires a shared library
that can't be found. Try the command "type zip". Maybe zip is located in
/usr/local/bin or somewhere else on your system.


> I'll see what my ISP has to say about the apparent, predominately
> un-locatable zip executable. They're not known for their fabulous customer
> service, so I fear this may be where the current avenue of exploration ends.
>
> I'll try to let you all know what happens.
>
> Muz.
>
>
>
>