| 1 | #!/bin/sh |
| 2 | |
| 3 | # This script takes a raw Windows event log and adds it to a |
| 4 | # previously built database generated by grokevt-builddb. |
| 5 | # See the man page for more details. |
| 6 | # |
| 7 | # Copyright (C) 2006 Timothy D. Morgan |
| 8 | # |
| 9 | # This program is free software; you can redistribute it and/or |
| 10 | # modify it under the terms of the GNU General Public License |
| 11 | # as published by the Free Software Foundation version 3 of the |
| 12 | # License. |
| 13 | # |
| 14 | # This program is distributed in the hope that it will be useful, |
| 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | # GNU General Public License for more details. |
| 18 | # |
| 19 | # $Id: grokevt-addlog 118 2011-06-20 16:06:43Z tim $ |
| 20 | |
| 21 | |
| 22 | usage() |
| 23 | { |
| 24 | echo "USAGE:" 1>&2 |
| 25 | echo " $0 <DATABASE_DIR> <EVT_FILE> <NEW_TYPE> <BASE_TYPE>" 1>&2 |
| 26 | echo 1>&2 |
| 27 | echo "This script takes a raw Windows event log and adds it to a" 1>&2 |
| 28 | echo "previously built database generated by grokevt-builddb." 1>&2 |
| 29 | echo "See the man page for more details." 1>&2 |
| 30 | } |
| 31 | |
| 32 | if [ $# -ne 4 ]; then |
| 33 | usage |
| 34 | exit 1 |
| 35 | fi |
| 36 | |
| 37 | DATABASE_DIR="$1" |
| 38 | EVT_FILE="$2" |
| 39 | NEW_TYPE="$3" |
| 40 | BASE_TYPE="$4" |
| 41 | |
| 42 | |
| 43 | if [ ! -d "$DATABASE_DIR" ]; then |
| 44 | echo "ERROR: '$DATABASE_DIR' is not a directory." 1>&2 |
| 45 | exit 2 |
| 46 | fi |
| 47 | |
| 48 | if [ ! -r "$EVT_FILE" ]; then |
| 49 | echo "ERROR: '$EVT_FILE' could not be read." 1>&2 |
| 50 | exit 2 |
| 51 | fi |
| 52 | |
| 53 | if [ -e "${DATABASE_DIR}/logs/${NEW_TYPE}.evt" ]; then |
| 54 | echo "ERROR: A '$NEW_TYPE' log already exists." 1>&2 |
| 55 | exit 2 |
| 56 | fi |
| 57 | |
| 58 | if [ ! -d "${DATABASE_DIR}/services/${BASE_TYPE}" ]; then |
| 59 | echo "ERROR: A '$BASE_TYPE' log does not exist." 1>&2 |
| 60 | exit 2 |
| 61 | fi |
| 62 | |
| 63 | |
| 64 | cp "$EVT_FILE" "${DATABASE_DIR}/logs/${NEW_TYPE}.evt"\ |
| 65 | || ( echo "ERROR: Could not copy log file." 1>&2; exit 3 ) |
| 66 | |
| 67 | ln -s "$BASE_TYPE" "${DATABASE_DIR}/services/${NEW_TYPE}"\ |
| 68 | || ( echo "ERROR: Could not create symlink to BASE_TYPE." 1>&2; exit 3 ) |