32 lines
600 B
Bash
Executable File
32 lines
600 B
Bash
Executable File
#!/bin/sh
|
|
|
|
set -e
|
|
|
|
find_host() {
|
|
zgrep -F "$(host "$1" | cut -d' ' -f4)" "$2" | tail -n1
|
|
}
|
|
|
|
if ! [ "$#" = 1 ]; then
|
|
echo "Invalid argument, use --help or -h for usage information." >&2
|
|
exit 1
|
|
fi
|
|
|
|
hostname=$1 && shift
|
|
|
|
if [ "$hostname" = "-h" ] || [ "$hostname" = "--help" ]; then
|
|
echo "nmgrep, find the last known information about a hostname"
|
|
echo "Usage: nmgrep <hostname> | --help | -h"
|
|
exit 0
|
|
fi
|
|
|
|
cd /var/log/netmonitor
|
|
|
|
for logfile in mappings.*; do
|
|
result=$(find_host "$hostname" "$logfile")
|
|
if ! [ -z "$result" ]; then
|
|
echo "$result"
|
|
exit 0
|
|
fi
|
|
done
|
|
exit 0
|