diff options
| author | spice <git@spice> | 2025-09-24 00:16:19 +0000 |
|---|---|---|
| committer | spice <git@spice> | 2025-09-24 00:16:19 +0000 |
| commit | e8c2c9f4f5bc997d67b330de982aef601ea31a55 (patch) | |
| tree | bde75c900fc8ea20d2fd1718e8ba56b3a2e6e7bb /autologs | |
Diffstat (limited to 'autologs')
| -rwxr-xr-x | autologs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/autologs b/autologs new file mode 100755 index 0000000..5359142 --- /dev/null +++ b/autologs @@ -0,0 +1,34 @@ +#!/usr/bin/env bash + +scriptlocalpath=""; +dbpass=''; + +PrepareInputFiles() { + local sincedate=$1; + local untildate=$2; + local inputfilename=$3; + journalctl -u ssh -S "${sincedate}" -U "${untildate}" > "${scriptlocalpath}/${inputfilename}"; +} + +ClearTempFiles() { + local UpperRangeShort=$(date '+%Y-%m' --date 'today'); + local inputfilename=$1; + if [ -f "${scriptlocalpath}/${inputfilename}" ]; then + mv "${scriptlocalpath}/${inputfilename}" "${scriptlocalpath}/backup/${UpperRangeShort}${inputfilename}"; + else + echo "did not find ${inputfilename} file"; + fi +} + +main() { + local UpperRangeShort=$(date '+%Y-%m' --date 'today'); + local LowerRangeShort=$(date '+%Y-%m' --date '1 week ago'); + local UpperRange="${UpperRangeShort}-01"; + local LowerRange="${LowerRangeShort}-01"; + local logfilename='sshlogs'; + PrepareInputFiles ${LowerRange} ${UpperRange} ${logfilename}; + python3 "${scriptlocalpath}/ssh_login_parser.py" ${LowerRange} ${UpperRange} ${logfilename} ${dbpass}; + ClearTempFiles ${logfilename}; +} + +main; |
