PeterErhard
asked on
PHP Shell Programming (Grep)
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_quer y.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;
************************** ********** *******
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
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_quer
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 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;
**************************
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Are you running same ksh from command line, or is it a different one?
ASKER
I'm using ksh when I run it manually, but not specificing anything through my PHP script. Do I need to? If so, how would I do that, to run that grep command?
It is specified by first line in your script, which is set to ksh also
#!/bin/ksh
Not sure why grep won't work, but it can be safer to quote special characters like the pipe symbol
#!/bin/ksh
Not sure why grep won't work, but it can be safer to quote special characters like the pipe symbol
ASKER
Sorry, but how are you suggesting I change this:
$output = shell_exec("grep \| temp_test.csv > test.csv");
$output = shell_exec("grep \| temp_test.csv > test.csv");
I was suggesting that in your script...
--------------
sqlplus -s pcms/pcms@pcms @dim_query.sql $1 $2
grep \| temp_test.csv > test.csv
************************** ********** *******
...you change the grep line to one of the following
grep '|' temp_test.csv > test.csv
grep '\|' temp_test.csv > test.csv
--------------
sqlplus -s pcms/pcms@pcms @dim_query.sql $1 $2
grep \| temp_test.csv > test.csv
**************************
...you change the grep line to one of the following
grep '|' temp_test.csv > test.csv
grep '\|' temp_test.csv > test.csv
ASKER
Ahh I see, thank you, will give it a try.
I don't have access right at the moment, but will report backin 10 hours time.
Thanks for your help so far :)
I don't have access right at the moment, but will report backin 10 hours time.
Thanks for your help so far :)
ASKER
I've tried:
egrep "\|" temp_test.csv > test.csv
egrep '|' temp_test.csv > test.csv
grep '|' temp_test.csv > test.csv
grep '\|' temp_test.csv > test.csv
and none of them work, but they do run fine at the command line :(
egrep "\|" temp_test.csv > test.csv
egrep '|' temp_test.csv > test.csv
grep '|' temp_test.csv > test.csv
grep '\|' temp_test.csv > test.csv
and none of them work, but they do run fine at the command line :(
ASKER
I used the below, and I had a permission problem, it's all fixed now :)
$output = shell_exec("./run_dim_quer y.sh $date1 $date2 2> /tmp/log");
I'll give you the points anyway, for helping me out.
$output = shell_exec("./run_dim_quer
I'll give you the points anyway, for helping me out.
thanx, glad its working for u.
ASKER
The weird thing is that when I run grep \| temp_test.csv > test.csv straight from the command line, it works perfectly :S