0

I am trying to fetch old exceptions logs from a application log file in linux. i am trying get the below query result in a variable using php. but getting below exception. Please help.

php code:

$Query= shell_exec (" grep -i -E 'ERROR|exception' applog.log | awk -v ts1="$(date --date=\'1 hours ago\' +\'%d/%m/%y %H:%M:%S.%3N\')" \'$2" "$3 > ts1 {print $0}\'|head -1 ");

Getting below exception:

PHP Parse error: syntax error, unexpected '$' in Exception.php on line 20

brombeer
  • 8,716
  • 5
  • 21
  • 27
  • You're trying to use unescaped double quotes inside a double quoted string. When you do that, PHP thinks you're ending your string, reading the text that _suppose_ to be inside double quotes as PHP code. You need to escape double quotes inside double quoted strings: `"foo \"foobar\" bar"` Read up on strings in PHP: https://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.double – M. Eriksson Sep 06 '21 at 07:03
  • Does [this](https://stackoverflow.com/questions/1255907/how-to-escape-php-exec-command-with-quotes) answer your question? – tink Sep 06 '21 at 07:09
  • Does this answer your question? [How to escape php exec() command with quotes](https://stackoverflow.com/questions/1255907/how-to-escape-php-exec-command-with-quotes) – Ivan Barayev Sep 06 '21 at 18:08

0 Answers0