[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

PHP Shell Programming (Grep)

Posted on 2006-05-18
2
Medium Priority
?
422 Views
Last Modified: 2012-05-05
I have the following script (see bottom of script) which runs fine, except for this part:

grep \| temp_test.csv > test.csv

It never runs this section for some reason.

I've tried adding

$output = shell_exec("grep \| /var/apache/htdocs/reports/temp_test.csv > /var/apache/htdocs/reports/test.csv");

and

$output = shell_exec("grep \| temp_test.csv > test.csv");

to the php file but it doesn't work either.

Any tips/suggestionbs on how to get this part going would be much appreciated.

******************************************

<?php

$Date1Day = $_POST["Date1Day"];
$Date1Month = $_POST["Date1Month"];
$Date1Year = $_POST["Date1Year"];
$Date2Day = $_POST["Date2Day"];
$Date2Month = $_POST["Date2Month"];
$Date2Year = $_POST["Date2Year"];

$date1 = $Date1Day . "/" . $Date1Month . "/" . $Date1Year;
$date2 = $Date2Day . "/" . $Date2Month . "/" . $Date2Year;

echo $date1;
echo "<br>";
echo $date2;

$output = shell_exec("./run_dim_query.sh $date1 $date2");

echo $output;

?>

**********************************************

The $output variable returns "Enter value for 1:", and doesn't carry on. Why is this?

**********************************************

#!/bin/ksh

export ORAENV_ASK=NO
export ORACLE_SID=client

. /usr/local/bin/oraenv

sqlplus -s pcms/pcms@pcms @dim_query.sql $1 $2

grep \| temp_test.csv > test.csv

*******************************************

WHENEVER SQLERROR EXIT 5
WHENEVER OSERROR EXIT 10
SET PAGESIZE 0
SET LINESIZE 500
SET FEEDBACK OFF
SET ECHO OFF

SPOOL temp_test.csv

SELECT DISTINCT rtrim(cd.cH_doc_id) || '|' ||
    rtrim(cm.attr_178) || '|' ||
    rtrim(cm.attr_97) || '|' ||
    rtrim(cd.title)  || '|' ||
    rtrim(cd.action_date) || '|' ||
    rtrim(cm.attr_179)
    FROM pcms_cm_catalogue cv,
               pcms_cm_phases cp,
               cm_attributes cm,
               pcms_chdoc_data cd
          WHERE cd.product_id in(Select distinct(product_id) from pcms_chdoc_data)
            AND cd.create_date BETWEEN TO_DATE('&1','MM/DD/YYYY') AND TO_DATE('&2','MM/DD/YYYY')
            AND cd.super_type LIKE '%'
            AND cd.ch_doc_type = 'WO'
            AND cd.status LIKE '%'
            AND cd.status != '$TO_BE_DEFINED'
            AND cd.ch_doc_id LIKE '%'
            AND cd.ch_uid = cm.ch_uid
            AND cd.cm_phase = cp.phase_id
            AND NVL (cd.seq, 1) = 1
            AND cp.phase_name LIKE '%'
            AND cd.ch_uid = cv.ch_uid
            AND cv.user_name LIKE '%';

SPOOL OFF

EXIT;

*******************************************
0
Comment
Question by:PeterErhard
2 Comments
 
LVL 5

Accepted Solution

by:
aminerd earned 2000 total points
ID: 16710383
I'd still recommend trying:

$output = shell_exec("./run_dim_query.sh $date1 $date2 2> /tmp/log");

If you're having a problem with the grep inside of run_dim_query.sh, you may never see it. This will redirect errors to /tmp/log so that you can see them.
0
 

Author Comment

by:PeterErhard
ID: 16713450
Thank you, that gave me a usual erro and I've fixed it :)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses
Course of the Month18 days, 17 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question