The problem: I am trying to run a shell script (on SuSE) from a PHP script, but while it doesn't give me an error it also doesn't do what it is supposed to do.
The shell script queries an MSSQL database and stores the results in a CSV file on my Linux server. The PHP script will then import the data to a MySQL database and use the data to send out email notifications of impending warranty expirations. I could just schedule subsequent cron jobs but you never know how many results you'll get from MSSQL, so the shell script could run a few seconds or a few hours.
Here's the PHP:
$err_log = shell_exec('/inet/ap/scripts/wty_notif.sh');
// If there are any shell messages, the script failed...
if($err_log !== "")
{
echo "Shell script failed with the following result:<br><br><em>$err_log</em>";
exit;
}
// Otherwise, continue...
Here's the script contents:
#!/bin/bash
cat /inet/ap/sql/wty_notif.sql | /usr/local/easysoft/unixODBC/bin/isql
MSDatabase username password -b -x0x09 > /inet/www/Temp/wty_results.csv
Here's the contents of wty_notif.sql:
SELECT * FROM AA_WTY_60_DAY_NOTICE_VW
Here's the MSSQL query results (just test data, for now):
U01 401SN8272 2008-06-01 00:00:00.000 2009-06-01 00:00:00.000
Data: company_code, job_number, wty_start_date, wty_end_date.
If I type "cat /inet/ap/sql/wty_notif.sql | /usr/local/easysoft/unixODBC/bin/isql MSDatabase username password -b -x0x09 > /inet/www/Temp/wty_results.csv" into the Linux console, it successfully creates a new wty_results.csv file with the results from the query. When I run the PHP script, it successfully gets to the end shell_exec() doesn't actually run the shell script.
Can anyone give me some insight?
Thanks!