Created
February 17, 2022 15:24
-
-
Save saidelike/1142fe9e7dd34b64caed7913e36ecca9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
file_to_compress="${2}" | |
path_to_logs="/run/log/" | |
compress_exit_code=0 | |
to_restart=0 | |
rm -f "${path_to_logs}"apache_error_log*.tar.gz | |
if [[ "${file_to_compress}" ]]; then | |
echo "Compressing ${file_to_compress} ..." | |
tar -czf "${file_to_compress}.tar.gz" "${file_to_compress}" | |
compress_exit_code=${?} | |
if [[ ${compress_exit_code} == 0 ]]; then | |
echo "File ${file_to_compress} was compressed." | |
echo "Check apache server status if needed to restart" | |
to_restart=$(awk 'match($10,/AH00288/,b){a[b[0]]++}END{for(i in a) if (a[i] > 5) print a[i]}' "${file_to_compress}") | |
if [ $to_restart -gt "5" ] | |
then | |
echo "Time to restart apache .." | |
rm -f "${path_to_logs}"apache_error_log* | |
systemctl restart apache2 | |
fi | |
rm -rf "${file_to_compress}" | |
else | |
echo "Error compressing file ${file_to_compress} (tar exit code: ${compress_exit_code})." | |
fi | |
fi | |
exit ${compress_exit_code} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment