The code is as follows: |
Copy code |
Check_php_syntax.sh
#! /Bin/bash # Check php syntax If [$ #-lt 1]; then Echo 'Usage: '$ 0' directory '; Exit Fi If [! -D $1]; then Echo $1 'not a directory, please check! '; Exit Fi Directory = $1 Temp_file = "/tmp/file $" # Echo $ temp_file Ls-R $ directory | awk' BEGIN { FS = "n" Folder = "'$ directory '" Logname = "'$ temp_file '" } { If ($0 ~ /. Php $ /){ System ("php-l" folder "/" $0 ">" logname "2> & 1 ") } If ($0 ~ /: $ /){ Folder = substr ($1, 1, length ($1)-1) } } ' If [-e $ temp_file]; then Cat $ temp_file | awk' BEGIN { Error = 0 } { If ($0 ~ /Parse /){ Error ++ Errorfile [$0] = $0 } } END { Print "error File:" error "files" If (length (errorfile)> 0) print "number of error rows :" For (I in errorfile) Print I } ' Else Echo "php file not found ." Exit; Fi |
For example:
The code is as follows: |
Copy code |
./Check_php_syntax/home/liuzhichao/test/
|
Output:
Error File: 2
Number of wrong lines:
PHP Parse error: syntax error, unexpected T_VARIABLE in/home/liuzhichao/test/awktest/a. php on line 3
PHP Parse error: syntax error, unexpected T_STRING, expecting ')' in/home/liuzhichao/test/levelcity. php on line 19