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


Groups > comp.lang.php > #14988

Re: Run AWK using shell_exec

From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Newsgroups comp.lang.php
Subject Re: Run AWK using shell_exec
Date 2015-02-27 14:17 +0100
Organization PointedEars Software (PES)
Message-ID <1456339.s4UYfUAo0h@PointedEars.de> (permalink)
References <bd5897d2-065d-4cf1-bd7f-cbcb3404cb25@googlegroups.com> <mcoev3$bt4$1@dont-email.me> <98db9ab8-dec1-4b3a-b790-285e967c64bb@googlegroups.com> <87egpcozxq.fsf@bsb.me.uk>

Show all headers | View raw


Ben Bacarisse wrote:

> "Dan'l B" <dan.hinckley@gmail.com> 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.

Back to comp.lang.php | Previous | NextPrevious in thread | Next 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