Sunday, April 2, 2023

more unix command line fun, grepping through apache error logs

 So I'm on a kick of trying to improve my site hygiene.

My Apache error_log is over 400Mb. I think mostly it's PHP warnings, especially " PHP Notice:  Undefined index: key" where I'm doing $_GET["propname"] without checking for isset. Guess that adds up for popular pages (and maybe running things in a loop?)

So I constructed this unix line:

grep -o "in \/home.*\.php.*" error_log | sort | uniq -c | sort -n -k1

So that says, pick out all the lines of form "in /home [blah blah] .php" and the -o means it just returns the match part (since other information like time stamp would be different)... I then "sort" (since the next command "uniq" only removes immediate duplicate lines, and "uniq -c" has an argument to count # of currences. Finally ChatGPT tells me "sort -n -k1" sorts numerically by the first field.

10240 in /home/kisrael/data/porchfest/COMMON/php_admin/db_view.php on line 156, referer: https://jpporchfest.org/adminstaff/db_view.php?datatype=band
19893 in /home/kisrael/data/porchfest/COMMON/php/formhelper.php on line 78
23958 in /home/kisrael/data/porchfest/COMMON/php/formhelper.php on line 79
24537 in /home/kisrael/data/porchfest/COMMON/php/formhelper.php on line 56
25107 in /home/kisrael/data/porchfest/COMMON/php/formhelper.php on line 73
25398 in /home/kisrael/data/porchfest/COMMON/php/formhelper.php on line 80
29532 in /home/kisrael/data/porchfest/COMMON/php_admin/db_view.php on line 85, referer: https://jpporchfest.org/adminstaff/
32909 in /home/kisrael/data/porchfest/COMMON/php_admin/db_viewCSV.php on line 46, referer: https://jpporchfest.org/adminstaff/
45156 in /home/kisrael/data/porchfest/COMMON/php_admin/db_view.php on line 156, referer: https://jpporchfest.org/adminstaff/edit.php?datatype=band
240618 in /home/kisrael/data/porchfest/COMMON/php_admin/db_view.php on line 156, referer: https://jpporchfest.org/adminstaff/

guess I got some work cut out for me!


No comments:

Post a Comment