Skip to content

Instantly share code, notes, and snippets.

@jtprogru
Last active February 15, 2023 17:46
Show Gist options
  • Save jtprogru/ecda34f7f7ff4f2652d9aad6236aa7cd to your computer and use it in GitHub Desktop.
Save jtprogru/ecda34f7f7ff4f2652d9aad6236aa7cd to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
"""
cat /var/log/nginx/access.log | sed -n '/2022:02:20/,/2022:02:23/p'| awk '{print $1}' | sort | uniq -c | sort -n | less
###
start_datetime = "15/Feb/2023:19:20"
end_datetime = "15/Feb/2022:02:23"
"""
def func_name_read_datetime_start_end():
"""
Функция, которая считывает дату и время начала и конца выборки
"""
pass
def func_name_for_cat_file():
"""
Функция, которая выводит содержимое access-лога куда-то
"""
access_log_file_path = "/var/log/nginx/access.log"
pass
def func_name_for_sed_datetime_range(start_datetime, end_datetime, content):
"""
Функция, которая выбирает все строки между start_datetime и end_datetime
"""
pass
def func_name_for_awk_print_ipaddr(clean_content):
"""
Функция, которая выбирается все IPv4-адреса
"""
pass
def func_name_for_awk_print_uri(clean_content):
"""
Функция, которая выводит все URI из лога
"""
pass
def func_name_for_sort(forward=False, content):
"""
Функция, которая сортирует
"""
pass
def func_name_for_uniq_count():
"""
Функция, которая считает количество уникальных штук
"""
pass
def main():
start, end = func_name_read_datetime_start_end()
file_content = func_name_for_cat_file()
neeeded_file_content = func_name_for_sed_datetime_range(start, end, file_content)
ipv4_addresses = func_name_for_awk_print_ipaddr(neeeded_file_content)
uris = func_name_for_awk_print_uri(neeeded_file_content)
ipv4_sorted = func_name_for_sort(True, ipv4_addresses)
uris_sorted = func_name_for_sort(False, uris)
result_ipv4 = func_name_for_uniq_count(ipv4_sorted)
result_uris = func_name_for_uniq_count(uris_sorted)
print(result_ipv4)
print(result_uris)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment