Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #14990

Re: Run AWK using shell_exec

From Jerry Stuckle <jstucklex@attglobal.net>
Newsgroups comp.lang.php
Subject Re: Run AWK using shell_exec
Date 2015-02-27 16:03 -0500
Organization A noiseless patient Spider
Message-ID <mcqm2h$372$1@dont-email.me> (permalink)
References (1 earlier) <mcoev3$bt4$1@dont-email.me> <98db9ab8-dec1-4b3a-b790-285e967c64bb@googlegroups.com> <87egpcozxq.fsf@bsb.me.uk> <1456339.s4UYfUAo0h@PointedEars.de> <eaaee751-7000-42c5-8fcd-d1acf595202a@googlegroups.com>

Show all headers | View raw


On 2/27/2015 2:40 PM, Dan'l B wrote:
> On Friday, February 27, 2015 at 8:18:49 AM UTC-5, Thomas 'PointedEars' Lahn wrote:
>> Ben Bacarisse wrote:
>>
>>> "Dan'l B"  writes:
>>>> Fails: (where $tidesFilePath is an absolute path to the fullyear.txt
>>>> file). $tidesFilePath = "/Tidefiles/fullyear.txt"; (example path)
>>>> $maxLow = shell_exec("/usr/bin/awk 'min==\"\" || $4~/^[^[:alpha:]]+$/
>>>> && $4 < min {min=$4} END{print min}'" . $tidesFilePath . \"");
>>>
>>> That's not syntactically correct PHP.  I'm not sure what the . \"" bit
>>> at the end is supposed to do, but you don't need it.  You *do* need a
>>> space between the end of the awk script in single quotes and the file
>>> name:
>>>
>>>  ... $4 < min {min=$4} END{print min}' " . $tidesFilePath);
>>>
>>> But you should be very careful when including variables into a shell
>>> command.  Never forget little Bobby Tables http://www.xkcd.com/327/
>>
>> Rule of thumb: Whenever you use any of the shell-accessing features, use 
>> escapeshellcmd() and escapeshellarg() as well.
>>
>> Whenever you find yourself using PHP's shell-accessing features to run an 
>> ad-hoc AWK script from PHP, you are doing something fundamentally wrong.  
>> PHP can do everything that AWK can do, and more (for example, it supports 
>> PCRE which even GNU awk does not), without requiring for that the additional 
>> privileges (and opening potential security leaks) that are required to run 
>> other programs from PHP.  This applies to ad-hoc sed(1) and perl(1) scripts 
>> as well.
>>
>> <http://php.net/escapeshellcmd>
>> <http://php.net/file_get_contents>
>> <http://php.net/preg_replace>
>>  
>> -- 
>> PointedEars
>> Zend Certified PHP Engineer
>> Twitter: @PointedEars2
>> Please do not cc me. / Bitte keine Kopien per E-Mail.
> 
> Thanks to one and all for the enlightening examples, pointers and lectures; very valuable for a noob like me.
> 

Dan'l,

Don't worry too much about what "Pointed Head" says.  He's a resident
troll; anyone who doesn't meet his specifications is "fundamentally wrong".

Using awk isn't necessarily the best way to do it, for a number of
reasons (i.e. many hosting companies have shell_exec() disabled due to
security reasons).  And yes, you *can* do most anything in PHP that you
can do in awk.

But that doesn't mean that awk is "fundamentally wrong".  It's just
another way of doing things.  And a new PHP programmer like yourself has
a lot of things to learn; I don't see using something you're already
familiar with (and have working in another environment) as being
"wrong".  You can always go back and change it later once you've learned
more PHP.


-- 
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================

Back to comp.lang.php | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Run AWK using shell_exec "Dan'l B" <dan.hinckley@gmail.com> - 2015-02-26 14:40 -0800
  Re: Run AWK using shell_exec Jerry Stuckle <jstucklex@attglobal.net> - 2015-02-26 19:50 -0500
    Re: Run AWK using shell_exec "Dan'l B" <dan.hinckley@gmail.com> - 2015-02-26 17:21 -0800
    Re: Run AWK using shell_exec "Dan'l B" <dan.hinckley@gmail.com> - 2015-02-26 17:41 -0800
      Re: Run AWK using shell_exec Jerry Stuckle <jstucklex@attglobal.net> - 2015-02-26 20:51 -0500
      Re: Run AWK using shell_exec Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-02-27 02:23 +0000
        Re: Run AWK using shell_exec "Dan'l B" <dan.hinckley@gmail.com> - 2015-02-26 19:11 -0800
          Re: Run AWK using shell_exec Matthew Carter <m@ahungry.com> - 2015-02-27 00:28 -0500
          Re: Run AWK using shell_exec Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-02-27 11:14 +0000
        Re: Run AWK using shell_exec Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-02-27 14:17 +0100
          Re: Run AWK using shell_exec "Dan'l B" <dan.hinckley@gmail.com> - 2015-02-27 11:40 -0800
            Re: Run AWK using shell_exec Jerry Stuckle <jstucklex@attglobal.net> - 2015-02-27 16:03 -0500

csiph-web