Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/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