Find and grep commands in PHP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ajd335
    New Member
    • Apr 2008
    • 123

    Find and grep commands in PHP

    Hi all,
    When I use the "find" and "grep" command on SSH shell gives me correct results.
    But when i use the same line in PHP....It's not working.

    The line of code is
    [code=sh]
    find 2008-06* -name "*.ps" -exec grep -i -e "lastname, firstname " {} \;
    [/code]
    In above I am giving the last name and first name.
    But when I am writing the above code in PHP , Its not giving me results. Here I want users to enter the last name and first name and accordingly search will be done.
    My PHP script is
    [code=php]
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
    <?php
    $title = "Grading Form";
    echo "Hello";
    if(isset($_POST['fname'])) { $f1 = $_POST['fname']; }
    echo $f1;
    if (isset($_POST['lname'])) { $ll = $_POST['lname']; }
    if (isset($_POST['add'])) { $a1 = $_POST['add']; }
    if (isset($_POST['date'])) { $d1 = $_POST['date']; }
    $query = ' find $date -name "*.ps" -exec grep -i -e $lname, $fname {} \ ' ;
    ?>
    [/code]
    Last edited by pbmods; Aug 11 '08, 10:47 PM. Reason: Fixed CODE tags.
  • coolsti
    Contributor
    • Mar 2008
    • 310

    #2
    Originally posted by ajd335
    Hi all,
    When I use the "find" and "grep" command on SSH shell gives me correct results.
    But when i use the same line in PHP....It's not working.

    The line of code is
    [code=sh]
    find 2008-06* -name "*.ps" -exec grep -i -e "lastname, firstname " {} \;
    [/code]
    In above I am giving the last name and first name.
    But when I am writing the above code in PHP , Its not giving me results. Here I want users to enter the last name and first name and accordingly search will be done.
    My PHP script is
    [code=php]
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
    <?php
    $title = "Grading Form";
    echo "Hello";
    if(isset($_POST['fname'])) { $f1 = $_POST['fname']; }
    echo $f1;
    if (isset($_POST['lname'])) { $ll = $_POST['lname']; }
    if (isset($_POST['add'])) { $a1 = $_POST['add']; }
    if (isset($_POST['date'])) { $d1 = $_POST['date']; }
    $query = ' find $date -name "*.ps" -exec grep -i -e $lname, $fname {} \ ' ;
    ?>
    [/code]
    What are you trying to do? You define a PHP variable called $query and set it to your shell command (incorrectly, however, see below), but what do you then do with your $query variable? From your example you have done nothing but define $query but you do not try to execute it.

    I also do not think you are doing what you really wish to do with the definition of the $query string. What are the values of $date, $lname and $fname? They are not set to anything in your code snippet. Also, you have these variables within single quotes rather than double quotes, so that the $query string will be defined without variable interpretation here.

    Comment

    • ajd335
      New Member
      • Apr 2008
      • 123

      #3
      Originally posted by coolsti
      .

      Hi CoolSti,
      First , I have one html coded page, which takes first name , last name , city and date from the user. Then it redirected to the php page( which is that code)..

      Further, the " query " results into one file name (e.g fil1.ps) ...I want to show on screen the name of the file as well as an option to print that file.
      I have not written code for that as my query itself is not working

      My question is , the find statment which works perfect in SSH , how can i use and store results of the same in PHP...

      Thanks

      Comment

      Working...