Scripts

From Michael's Information Zone
Revision as of 12:22, 21 February 2018 by Michael.mast (talk | contribs) (→‎Files)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Backup

Files

Reporting

  • Apache logs. This was from a production environment, I had a list of users to IP addresses in another location and this would replace IPs with user names. It also removes some backend stuff used with word press and Apache.
#!/bin/bash
grep GET /var/log/httpd/access_log | grep https://yoursite.tld/ | sed 's|/var/log/httpd/access_log-[0-9]\+:||; s|-\ -\ \[||; s|-[0-9]\{4\}||; s|\ \]||; s|GET||; /ccm/d; /tools/d; /dashboard/d; /index.php\ HTTP/d' | sed '/\/index.php\/login/d; s|HTTP/1.1||; /cID=/d' | awk -F\" '{ print $1 $2 }' | grep index.php > /tmp/logtest

while read line;
do
	ip=$(awk '{ print $1 }' <<<$line)
#	echo $ip
	username=$(files=$(grep -R $ip /mnt/fs01/ | awk '{ print $3 }'); while read line; do ls -al --time-style=+s $line; done <<<$files | awk '{ print $5 $7}' | sort -r | head -1 | sed 's/^[0-9]\+//' | awk -F\/ '{ print $4 }' | sed 's/^[0-9a-zA-Z-]\+\.//; s/\.txt//')
	if [ -v $username ]; then
	username="$ip"
	fi
	sed "s/$ip/$username/" <<<$line
	done < /tmp/logtest
rm -f /tmp/logtest

Interfacing With Windows Domain

Misc