Skip to content
Snippets Groups Projects
Commit b334e554 authored by Edileuton Henrique de Oliveira's avatar Edileuton Henrique de Oliveira
Browse files

agent: Add script that collect the logeed users in the host

parent 46ffd718
No related branches found
No related tags found
No related merge requests found
#!/bin/bash
# Copyright (C) 2009-2012 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
#
# This file is part of collect-agent
#
# collect-agent is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.
# run datasid-common.sh
source "$(readlink -f "$(dirname $0)/../")/bin/datasid-common.sh" || exit 1
if test -z "${PREFIX}"; then
exit 2
fi
oldIFS=$IFS
IFS=$'\n'
count=0;
for line in $(last -F);
do
Date=$(echo $line | awk '{ print $5" "$6" "$7" "$8}')
# Check if is the user system
if ! echo $line | grep -q system; then
userSeconds=$(date -d $Date +%s)
oldSeconds=$(cat ${DATADIR}/lastexec)
# Check if the user must be collected
if ((${userSeconds} < ${oldSeconds})); then
IFS=$oldIFS
exit 0
fi
login=$(echo $line | awk '{print $1}')
in_time=$(echo $line | awk '{print $7}')
out_time=$(echo $line | awk '{print $13}')
if test -z $out_hour; then
out_hour=$(echo $line | awk '{print $10}')
fi
count=$(($count+1))
printf "<user$count>\n"
printf "<login value=\"$login\" type =\"string\"/>"
printf "<in_time value=\"$in_hour\" type =\"string\"/>"
printf "<out_time value=\"$out_hour\" type =\"string\"/>"
printf "</user$count>\n"
fi
done
IFS=$oldIFS
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment