Difference between revisions of "Scripts"
Jump to navigation
Jump to search
Michael.mast (talk | contribs) |
Michael.mast (talk | contribs) |
||
Line 5: | Line 5: | ||
==Reporting== | ==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. | ||
+ | <pre> | ||
+ | #!/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 | ||
+ | </pre> | ||
==Interfacing With Windows Domain== | ==Interfacing With Windows Domain== |
Revision as of 15:46, 15 December 2017
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