I've created a web page that converts bash line breaks [ ] to HTML line breaks [< br />]. This works by having the web page call
shell_exec("bash /xxx/xxx/script.sh");
Inside the bash script.sh, it runs a series of SQL queries to replace the bash line breaks with html line breaks, allowing me to format the SQL data into an HTML based email.
`mysql -uXXX -pXXX -e "UPDATE tbl SET var = REPLACE(var, '
', '<br />')" db`
When I run this bash script via Linux cli, it runs perfect, and the email it sends out uses HTML line breaks. But when I run the script via shell_exec, it just shows in plain text, the bash line break code [ ].
Here is a sample of the email output when running the bash script with PHP shell_exec.
[ var1 ]
test test test
test test test
test some more
[ var2 ]
test test
test
test
And a sample when I run the bash script from linux.
[ var1 ]
test test test
test test test
test some more
[ var2 ]
test test
test
test
I know my other SQL queries work such as SELECT MAX(id) [grabbing the appropriate row and data fields]. Any idea as to why the same script runs perfectly fine under linux bash (to run SQL query, replacing line breaks), but not by calling it with PHP shell_exec? Am I missing something here?
* httpd error log states: sudo: sorry, you must have a tty to run sudo
and when I enable: sudo: no tty present and no askpass program specified
Could this be a TTY issue since it's a command/script being called by user apache? If so, any work arounds?