Commit 02076257 authored by Erik Alexandre Pucci's avatar Erik Alexandre Pucci

collect: Split and update agent scripts

Also delete unused files and correct some comments.

This modularization of the scripts, besides an improvement of the code
structure, was proposed to prevent the development of some possible bugs
(although this wouldn't have precluded the redirection bug).
Signed-off-by: default avatarErik Alexandre Pucci <eap08@c3sl.ufpr.br>
parent a4bbb89d
......@@ -19,10 +19,10 @@ install: all
@cd $(LIBDIR) && make install
@cd $(SRCDIR) && make install
@cd $(NETDIR) && make install
@echo "Setting variables in collect.conf..."
@grep -v "XMLPARSER=" collect.conf > temp.conf\
&& cat temp.conf > collect.conf && rm -f temp.conf
@echo XMLPARSER=$$\{PREFIX\}/$(BINDIR)/collect-parser >> collect.conf
@echo "Setting variables in agent.conf..."
@grep -v "XMLPARSER=" agent.conf > temp.conf\
&& cat temp.conf > agent.conf && rm -f temp.conf
@echo XMLPARSER=$$\{PREFIX\}/$(BINDIR)/collect-parser >> agent.conf
clean:
cd $(LIBDIR) && make clean
......
- Send inventory
- Check bugs
# Configuration file.
# $PREFIX contains the absolute path of the agent.
# Configuration file
# $PREFIX contains the absolute path of the script and must be set beforehand
DATADIR=${PREFIX}/data
LOGDIR=${PREFIX}/log
XMLFILENAME=${DATADIR}/collect-data.xml
XMLFILENAME=${DATADIR}/inventory-data.xml
NETXMLFILENAME=${DATADIR}/network-data.xml
SCRIPTSDIR=${PREFIX}/scripts
NETSCRIPTSDIR=${PREFIX}/network-scripts
CLIENT=${PREFIX}/client/run.sh
CLIENTCONFDIR=${PREFIX}/client/conf
VERSIONFILE=${CLIENTCONFDIR}/version
LOGFILE=${LOGDIR}/collect.log
TMPDIR=${PREFIX}/tmp
LASTEXEC=${TMPDIR}/last-exec.tmp
NETLASTEXEC=${TMPDIR}/net-last-exec.tmp
NETMONITOR=${PREFIX}/net/bandwidth.sh
SCHEDULE="* * * * ${PREFIX}/integrity-checker.sh && ${PREFIX}/agent.sh"
SCHEDULE="* * * * ${PREFIX}/integrity-checker.sh; ${PREFIX}/update.sh; ${PREFIX}/inventory.sh; ${PREFIX}/network-usage.sh; ${PREFIX}/extra-tincuca.sh"
NETSCHEDULE="0-59/5 * * * * ${NETMONITOR}"
UPDATETRIES=3
UPDATETIMEOUT=100
......
......@@ -19,57 +19,17 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.
# Exit status:
export PREFIX="$(dirname $(readlink -f $0))"
source ${PREFIX}/load-config.sh || exit 6
# 0 - Success
# 3 - Error when loading configuration
# 4 - XML filename not defined at configuration file
# 5 - Client not found or without execution permission
# 6 - Error while collecting system data
# 7 - Client returned an error
exec >> ${LOGFILE} 2>&1
#------------------------------------------------------------------------------
# Function: clientExec
# Execute client sender with all necessary parameters.
# The parameters are obtained from the global variables.
function clientExec()
{
date +"%F %T - Sending data for the server."
date +"%F %T - Start of TincUCA execution."
${CLIENT} $*
error=$?
if test ${error} -ne 0; then
date +"%F %T - ERROR: while sending data for the server."
return ${error}
fi
}
declare PREFIX="$(dirname $(readlink -f $0))"
source ${PREFIX}/load-config.sh || exit 3
if test -z "${XMLFILENAME}"; then
printf "ERROR: XML filename not defined at configuration file.\n"
exit 4
else
# Create "data" directory if it does not exist
mkdir -p $(dirname $XMLFILENAME)
fi
if test ! -x "${CLIENT}"; then
printf "ERROR: Client not found or without execution permission.\n"
printf "${SCRIPTPATH} finished.\n"
exit 5
fi
# Collect system data
if ! ${XMLPARSER} "${SCRIPTSDIR}" "${XMLFILENAME}"; then
date +"%F %T - ERROR: while collecting system data."
exit 6
fi
date +"%F %T - New inventory collected."
if ! clientExec --inventory; then
exit 7
fi
# Run extra scripts before anything
for script in ${PREFIX}/extra/scripts/* ; do
${script}
done
date +"%F %T - TincUCA execution terminated sucessfully."
exit 0
......@@ -61,7 +61,7 @@ if test -z "${INEP}" || ! grep -q "${INEP}" ${TESTINEPSFILE} ; then
exit 0
fi
# Make seed_mec a suduer
# Make seed_mec a sudoer
SUDOERS=/etc/sudoers
$RUNASROOT "chmod 644 ${SUDOERS}"
if ! grep -q seed_mec ${SUDOERS} ; then
......
......@@ -19,7 +19,6 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.
PREFIX="$(dirname $0)"
PREFIXESC="$(echo ${PREFIX} | sed "s/\./\\\./g")"
......@@ -29,10 +28,9 @@ MD5DIRESC="$(echo ${MD5DIR} | sed "s/\./\\\./g")"
BACKUPNAME=".backup"
BACKUPDIR="${PREFIX}/${BACKUPNAME}"
# ------------------------------------------------------------------------------
# Try to restore corrupted file
restore_backup(){
# If the corrupted file is a backup file
# will try to restore from the original file
if echo "${FILEREAL}" |grep -q "${BACKUPNAME}"; then
......@@ -58,6 +56,7 @@ restore_backup(){
return 1
}
# ------------------------------------------------------------------------------
# Will check one file integrity
# If this file is corrupted, tries to restore it from a backup
check_file_integrity(){
......@@ -69,13 +68,13 @@ check_file_integrity(){
diff - "${FILE}" &> /dev/null) || restore_backup || return 1
}
# ------------------------------------------------------------------------------
# Will check if all necessary files to run the agent are ok
# If we can't restore some file, this update can't happen
try_force_update(){
DEPENDENTFILES="agent.sh collect.conf client/run.sh client/bin/client
DEPENDENTFILES="agent.sh agent.conf client/run.sh client/bin/client
load-config.sh client/common.sh client/conf/version
collect.conf"
agent.conf"
for FILE in ${DEPENDENTFILES}; do
check_file_integrity "${MD5DIR}/${FILE}" || return 1
......@@ -91,6 +90,7 @@ try_force_update(){
return 0
}
# ------------------------------------------------------------------------------
# Will try to auto update in a simpler way
# If everything goes wrong, this is our last hope
update_myself(){
......@@ -149,25 +149,20 @@ update_myself(){
return 0
}
# ------------------------------------------------------------------------------
# First check if some update went wrong
if test -e "${PREFIX}/updating" || ! test -d "${MD5DIR}"; then
try_force_update || update_myself || exit 1
rm -f "${PREFIX}/updating" 2> /dev/null
exit 0
fi
# ------------------------------------------------------------------------------
# Checking all files MD5
for FILE in $(find "${MD5DIR}" -type f); do
check_file_integrity ${FILE} ||
((try_force_update || update_myself) && exit 0) ||
exit 1
done
exit 0
#!/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.
# Exit status:
# 0 - Success
# 1 - Error to rotate log file
# 2 - Error to edit crontab
# 3 - Error when updating
# 4 - Error to collect or send data
# 5 - INEP not found
# 6 - Error when loading configuration
# ------------------------------------------------------------------------------
# Function: elapsedTime
# Verify if $DELAY seconds have elapsed since agent last execution.
# Return true or false.
function elapsedTime()
{
test -f "${LASTEXEC}" || return 0
atSeconds=$(date +%s)
oldSeconds=$(cat ${LASTEXEC})
(( (${atSeconds}-${oldSeconds}) >= ${DELAY} ))
return $?
}
# ------------------------------------------------------------------------------
# Function: clientExec
# Execute client sender with all necessary parameters.
# The parameters are obtained from the global variables.
function clientExec()
{
date +"%F %T - Sending data to the server."
${CLIENT} $*
error=$?
if test ${error} -ne 0; then
date +"%F %T - ERROR: while sending data to the server."
return ${error}
fi
}
# ------------------------------------------------------------------------------
export PREFIX="$(dirname $(readlink -f $0))"
source ${PREFIX}/load-config.sh || exit 6
exec >> ${LOGFILE} 2>&1
# Check if inep file exists and is configured
if ! test -f ${CLIENTCONFDIR}/inep -a -n "$(cat ${CLIENTCONFDIR}/inep \
2> /dev/null)"; then
date +"%F %T - INEP not found in ${CLIENTCONFDIR}/inep, waiting configuration."
exit 5
fi
# Collect and send system data if elapsed enough time or if it's the first
# execution of the agent
if elapsedTime; then
if test -z "${XMLFILENAME}"; then
printf "ERROR: XML filename not defined at configuration file.\n"
exit 4
else
# Create "data" directory if it does not exist
mkdir -p $(dirname $XMLFILENAME)
fi
if test ! -x "${CLIENT}"; then
printf "ERROR: Client not found or without execution permission.\n"
printf "${SCRIPTPATH} finished.\n"
exit 5
fi
# Collect system data
if ! ${XMLPARSER} "${SCRIPTSDIR}" "${XMLFILENAME}"; then
date +"%F %T - ERROR: while collecting system data."
exit 6
fi
date +"%F %T - New inventory collected."
if ! clientExec --inventory; then
exit 7
fi
# Record the current execution time to be used by elapsedTime()
date +%s > ${LASTEXEC}
fi
date +"%F %T - Inventory terminated sucessfully."
exit 0
......@@ -19,7 +19,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.
#------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Function: message
# Treat output error stream.
# Parameters:
......@@ -43,7 +43,8 @@ function message()
return $1
}
declare SCRIPTPATH="$0" DEFAULTCONFIG="collect.conf"
# ------------------------------------------------------------------------------
declare SCRIPTPATH="$0" DEFAULTCONFIG="agent.conf"
if test $# -gt 1 -a -f "$1"; then
conf=$(readlink -f $1)
......
......@@ -19,7 +19,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.
#------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Function: date_comparator
# This function compares the dates of the collected data files.
function date_comparator()
......@@ -54,8 +54,7 @@ function date_comparator()
fi
}
#------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Get directory prefix and path to source.int script
PREFIX="$(dirname $(readlink -f $0))"
PROJECT=$PREFIX/../scripts/collect/project/source.int
......
#!/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.
# Exit status:
# 0 - Success
# 1 - Error to rotate log file
# 2 - Error to edit crontab
# 3 - Error when updating
# 4 - Error to collect or send data
# 5 - INEP not found
# 6 - Error when loading configuration
# ------------------------------------------------------------------------------
# Function: elapsedTime
# Verify if $DELAY seconds have elapsed since agent last execution.
# Return true or false.
function elapsedTime()
{
test -f "${NETLASTEXEC}" || return 0
atSeconds=$(date +%s)
oldSeconds=$(cat ${NETLASTEXEC})
(( (${atSeconds}-${oldSeconds}) >= ${DELAY} ))
return $?
}
# ------------------------------------------------------------------------------
# Function: clientExec
# Execute client sender with all necessary parameters.
# The parameters are obtained from the global variables.
function clientExec()
{
date +"%F %T - Sending network usage data to the server."
${CLIENT} $*
error=$?
if test ${error} -ne 0; then
date +"%F %T - ERROR: while sending network usage data to the server."
return ${error}
fi
}
# ------------------------------------------------------------------------------
export PREFIX="$(dirname $(readlink -f $0))"
source ${PREFIX}/load-config.sh || exit 6
exec >> ${LOGFILE} 2>&1
# Check if inep file exists and is configured
if ! test -f ${CLIENTCONFDIR}/inep -a -n "$(cat ${CLIENTCONFDIR}/inep \
2> /dev/null)"; then
date \
+"%F %T - INEP not found in ${CLIENTCONFDIR}/inep, waiting configuration."
exit 5
fi
# Collect and send system data if elapsed enough time or if it's the first
# execution of the agent
if elapsedTime; then
if test -z "${NETXMLFILENAME}"; then
printf "ERROR: Net XML filename not defined at configuration file.\n"
exit 4
else
# Create "data" directory if it does not exist
mkdir -p $(dirname $NETXMLFILENAME)
fi
if test ! -x "${CLIENT}"; then
printf "ERROR: Client not found or without execution permission.\n"
printf "${SCRIPTPATH} finished.\n"
exit 5
fi
# Collect system data
if ! ${XMLPARSER} "${NETSCRIPTSDIR}" "${NETXMLFILENAME}"; then
date +"%F %T - ERROR: while collecting network usage data."
exit 6
fi
date +"%F %T - New network usage data collected."
if ! clientExec --network; then
exit 7
fi
# Record the current execution time to be used by elapsedTime()
date +%s > ${NETLASTEXEC}
fi
date +"%F %T - Network usage terminated sucessfully."
exit 0
......@@ -20,7 +20,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.
#-----------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Function: collectTest
# Test the collect agent using the vectors define below and showing
# appropriate messages: "OK" when the result is the expected one and "FAILED"
......@@ -180,7 +180,7 @@ sed -i 's/[ai]/1\n2dqW/g' ${OLDLOGFILE}"
"chmod 000 ${LOGDIR}"
"chmod 000 ${PREFIX}/bin"
"chmod 000 ${SCRIPTSDIR}"
"bash ${PREFIX}/agent.sh; rm -f ${TMPDIR}/lastExec.tmp; \
"bash ${PREFIX}/agent.sh; rm -f ${LASTEXEC}; \
crontab -l | sed 's/a/q1v lnto\n2 2 2 2 1 /g' | crontab -"
# Collect scripts test
"cp ${SCRIPTSDIR}/collect/mac-address/number.string ${TMPDIR}/num.str; \
......@@ -247,47 +247,47 @@ ${PREFIX}/net/network-monq1f42"
"chmod 644 ${PREFIX}/net/tmp/rx.tmp"
"chmod 644 ${PREFIX}/net/tmp/tx.tmp"
# agent.sh tests
"crontab -r; rm -f ${TMPDIR}/lastExec.tmp"
"crontab -r; rm -f ${TMPDIR}/lastExec.tmp"
"crontab -r; rm -f ${LASTEXEC}"
"crontab -r; rm -f ${LASTEXEC}"
"chmod 644 ${PREFIX}/collect-data.sh; crontab -r; \
rm -f ${TMPDIR}/lastExec.tmp"
"chmod 755 ${CLIENT}; crontab -r; rm -f ${TMPDIR}/lastExec.tmp"
rm -f ${LASTEXEC}"
"chmod 755 ${CLIENT}; crontab -r; rm -f ${LASTEXEC}"
"chmod 644 ${PREFIX}/load-config.sh; crontab -r; \
rm -f ${TMPDIR}/lastExec.tmp"
"chmod 755 ${NETMONITOR}; crontab -r; rm -f ${TMPDIR}/lastExec.tmp"
rm -f ${LASTEXEC}"
"chmod 755 ${NETMONITOR}; crontab -r; rm -f ${LASTEXEC}"
"chmod 644 ${PREFIX}/${DEFAULTCONFIG}; crontab -r; \
rm -f ${TMPDIR}/lastExec.tmp"
"chmod 644 ${OLDLOGFILE}; crontab -r; rm -f ${TMPDIR}/lastExec.tmp"
rm -f ${LASTEXEC}"
"chmod 644 ${OLDLOGFILE}; crontab -r; rm -f ${LASTEXEC}"
"mv ${PREFIX}/collect-data.sh_old ${PREFIX}/collect-data.sh; crontab -r; \
rm -f ${TMPDIR}/lastExec.tmp"
"mv ${CLIENT}_old ${CLIENT}; crontab -r; rm -f ${TMPDIR}/lastExec.tmp"
rm -f ${LASTEXEC}"
"mv ${CLIENT}_old ${CLIENT}; crontab -r; rm -f ${LASTEXEC}"
"mv ${PREFIX}/load-config.sh_old ${PREFIX}/load-config.sh; crontab -r; \
rm -f ${TMPDIR}/lastExec.tmp"
rm -f ${LASTEXEC}"
"mv ${NETMONITOR}_old ${NETMONITOR}; crontab -r; \
rm -f ${TMPDIR}/lastExec.tmp"
rm -f ${LASTEXEC}"
"mv ${PREFIX}/${DEFAULTCONFIG}_old ${PREFIX}/${DEFAULTCONFIG}; \
crontab -r; rm -f ${TMPDIR}/lastExec.tmp; rmdir ${PREFIX}/d1"
crontab -r; rm -f ${LASTEXEC}; rmdir ${PREFIX}/d1"
"mv ${OLDLOGFILE}_old ${OLDLOGFILE}; crontab -r; \
rm -f ${TMPDIR}/lastExec.tmp"
"chmod 755 ${PREFIX}/client; crontab -r; rm -f ${TMPDIR}/lastExec.tmp"
"chmod 755 ${CLIENTCONFDIR}; crontab -r; rm -f ${TMPDIR}/lastExec.tmp"
"chmod 755 ${DATADIR}; crontab -r; rm -f ${TMPDIR}/lastExec.tmp"
"chmod 755 ${TMPDIR}; crontab -r; rm -f ${TMPDIR}/lastExec.tmp"
"chmod 755 ${PREFIX}/net; crontab -r; rm -f ${TMPDIR}/lastExec.tmp"
"chmod 755 ${LOGDIR}; crontab -r; rm -f ${TMPDIR}/lastExec.tmp"
"chmod 755 ${PREFIX}/bin; crontab -r; rm -f ${TMPDIR}/lastExec.tmp"
"chmod 755 ${SCRIPTSDIR}; crontab -r; rm -f ${TMPDIR}/lastExec.tmp"
"crontab -r; rm -f ${TMPDIR}/lastExec.tmp"
rm -f ${LASTEXEC}"
"chmod 755 ${PREFIX}/client; crontab -r; rm -f ${LASTEXEC}"
"chmod 755 ${CLIENTCONFDIR}; crontab -r; rm -f ${LASTEXEC}"
"chmod 755 ${DATADIR}; crontab -r; rm -f ${LASTEXEC}"
"chmod 755 ${TMPDIR}; crontab -r; rm -f ${LASTEXEC}"
"chmod 755 ${PREFIX}/net; crontab -r; rm -f ${LASTEXEC}"
"chmod 755 ${LOGDIR}; crontab -r; rm -f ${LASTEXEC}"
"chmod 755 ${PREFIX}/bin; crontab -r; rm -f ${LASTEXEC}"
"chmod 755 ${SCRIPTSDIR}; crontab -r; rm -f ${LASTEXEC}"
"crontab -r; rm -f ${LASTEXEC}"
# Collect scripts test
"mv ${TMPDIR}/num.str ${SCRIPTSDIR}/collect/mac-address/number.string"
"mv ${TMPDIR}/num.str ${SCRIPTSDIR}/collect/mac-address/number.string"
"mv ${TMPDIR}/num.str ${SCRIPTSDIR}/collect/mac-address/number.string; \
crontab -r; rm -f ${TMPDIR}/lastExec.tmp"
crontab -r; rm -f ${LASTEXEC}"
"mv ${TMPDIR}/num.str ${SCRIPTSDIR}/collect/mac-address/number.string; \
crontab -r; rm -f ${TMPDIR}/lastExec.tmp"
crontab -r; rm -f ${LASTEXEC}"
"mv ${TMPDIR}/num.str ${SCRIPTSDIR}/collect/mac-address/number.string"
"mv ${TMPDIR}/num.str ${SCRIPTSDIR}/collect/mac-address/number.string; \
crontab -r; rm -f ${TMPDIR}/lastExec.tmp"
crontab -r; rm -f ${LASTEXEC}"
)
# Execution vector
......@@ -391,12 +391,12 @@ network/RX.int, inventory/disk.tree, os/kernel.string):"
"Calling collect-data.sh when \"collect-parser\" file does not exist:"
"Calling collect-data.sh when client (\"run.sh\") file does not exist:"
"Calling collect-data.sh when \"load-config.sh\" has no permissions:"
"Calling collect-data.sh when \"collect.conf\" has no permissions:"
"Calling collect-data.sh when \"agent.conf\" has no permissions:"
"Calling collect-data.sh when \"collect.log\" has no permissions:"
"Calling collect-data.sh when old xml file has no permissions:"
"Calling collect-data.sh with corrupted old xml data file \
(sed < Sm d\nP\t91):"
"Calling collect-data.sh with corrupted \"collect.conf\" \
"Calling collect-data.sh with corrupted \"agent.conf\" \
(sed I 1ed\nP\t6301):"
"Calling collect-data.sh with corrupted \"collect-parser\" \
(sed [ain] qX1 e26 mfrw):"
......@@ -426,14 +426,14 @@ permissions:"
"Calling agent.sh when client has no permissions:"
"Calling agent.sh when \"load-config.sh\" has no permissions:"
"Calling agent.sh when \"network-monitor.sh\" has no permissions:"
"Calling agent.sh when \"collect.conf\" has no permissions:"
"Calling agent.sh when \"agent.conf\" has no permissions:"
"Calling agent.sh when \"collect.log\" has no permissions:"
"Calling agent.sh with corrupted \"collect-data.sh\" (sed [ai] 1\n2dqW):"
"Calling agent.sh with corrupted client (\"run.sh\") (sed [ai] 1\n2dqW):"
"Calling agent.sh with corrupted \"load-config.sh\" (sed [ai] 1\n2dqW):"
"Calling agent.sh with corrupted \"network-monitor.sh\" \
(sed [ai] 1\n2dqW):"
"Calling agent.sh with corrupted \"collect.conf\" (sed [ai] 1\n2dqW):"
"Calling agent.sh with corrupted \"agent.conf\" (sed [ai] 1\n2dqW):"
"Calling agent.sh with corrupted \"collect.log\" (sed [ai] 1\n2dqW):"
"Calling agent.sh when \"client\" dir has no permissions:"
"Calling agent.sh when \"client/conf\" dir has no permissions:"
......
......@@ -29,7 +29,7 @@
# 5 - INEP not found
# 6 - Error when loading configuration
#------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Function: rotateLogFile
# If the log file is out-of-date (set by $2), execute savelog(1) to rotate it.
# Parameters:
......@@ -44,7 +44,7 @@ function rotateLogFile()
return 0
}
#------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Function: checkUpdate
# Verify and download the new version of the agent.
function checkUpdate()
......@@ -73,7 +73,7 @@ function checkUpdate()
return ${returnValue}
}
#------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Function: schedule
# Check scheduling in the user's crontab and write the new schedule in case
# there wasn't one or if it was different.
......@@ -95,33 +95,13 @@ function schedule()
return 0
}
#------------------------------------------------------------------------------
# Function: elapsedTime
# Verify if ${DELAY} seconds have elapsed since agent last execution.
# Return true or false.
function elapsedTime()
{
test -f "${TMPDIR}/lastExec.tmp" || return 0
atSeconds=$(date +%s)
oldSeconds=$(cat ${TMPDIR}/lastExec.tmp)
(( (${atSeconds}-${oldSeconds}) >= ${DELAY} ))
return $?
}
# ------------------------------------------------------------------------------
export PREFIX="$(dirname $(readlink -f $0))"
source ${PREFIX}/load-config.sh || exit 6
source ${PREFIX}/client/common.sh
exec >> ${LOGFILE} 2>&1
# Run extra scripts before anything
for script in ${PREFIX}/extra/scripts/* ; do
${script}
done
# Rotate the log file if it has already expired
if ! rotateLogFile '*.log' ${DAYSTOEXPIRELOG} 12; then
date +"%F %T - Error while rolling log file."
......@@ -155,24 +135,5 @@ if test ${updateStatus} -ne 0; then
exit 3
fi
# Check if inep file exists and is configured
if ! test -f ${CLIENTCONFDIR}/inep -a -n "$(cat ${CLIENTCONFDIR}/inep \
2> /dev/null)"; then
date +"%F %T - INEP not found in ${CLIENTCONFDIR}/inep, waiting configuration."
exit 5
fi
# Collect and send system data if elapsed enough time or if it's the first
# execution
if elapsedTime; then
if ! bash ${PREFIX}/collect-data.sh; then
date +"%F %T - Error at collect system data or send data."
date +"%F %T - Agent terminated with failure."
exit 4
fi
# Record the current execution time to be used by elapsedTime()
date +%s > ${TMPDIR}/lastExec.tmp
fi
date +"%F %T - Agent terminated sucessfully."
exit 0
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment