nut-debian/tools/nut-ddl-dump.sh

66 lines
2.5 KiB
Bash
Raw Permalink Normal View History

2015-04-30 16:53:36 +03:00
#!/bin/sh
################################################################################
# A script to ease the generation of NUT device dumps for NUT Devices Dumps Library
################################################################################
# Author: (C) Arnaud Quette <ArnaudQuette@Eaton.com>
# License: GPL v2+
################################################################################
# FIXME:
# - check if a previous report exists, and increase report number
#  - we currently use the .dev format ; but also consider the NDS format
# http://www.networkupstools.org/ddl/
################################################################################
strUsage="Usage: $0 <device_name>"
# Check command line parameter (<device_name>)
if [ -z "$1" ]; then
echo "$strUsage"
exit
else
DDL_DEVICE_NAME=$1
fi
# Test communication with the device
2022-07-10 10:23:45 +03:00
upscResult="`upsc ${DDL_DEVICE_NAME} 2> /dev/null`"
2015-04-30 16:53:36 +03:00
if [ $? -gt 0 ]; then
echo "Can't communicate with ${DDL_DEVICE_NAME}"
exit
fi
2022-07-10 10:23:45 +03:00
# Collect more information
dumpDate="`date -R`"
upsrwResult="`upsrw ${DDL_DEVICE_NAME} 2> /dev/null`"
upscmdResult="`upscmd -l ${DDL_DEVICE_NAME} 2> /dev/null`"
2015-04-30 16:53:36 +03:00
# Build the filename
# <manufacturer>__<model>__<driver-name>__<nut-version>__<report-number>.<extension>
2022-07-10 10:23:45 +03:00
# Process the Manufacturer name
2015-04-30 16:53:36 +03:00
RAW_DDL_MFR="`upsc ${DDL_DEVICE_NAME} device.mfr 2>/dev/null`"
if [ "${RAW_DDL_MFR}" = "EATON" ]; then
RAW_DDL_MFR="Eaton"
fi
# Replace spaces with underscores
DDL_MFR="`echo ${RAW_DDL_MFR} | sed s/\ /_/g`"
2022-07-10 10:23:45 +03:00
# Process the Model name
2015-04-30 16:53:36 +03:00
# Replace spaces with underscores
RAW_DDL_MODEL="`upsc ${DDL_DEVICE_NAME} device.model 2>/dev/null`"
DDL_MODEL="`echo ${RAW_DDL_MODEL} | sed s/\ /_/g`"
# Process the driver name and NUT version
DDL_DRIVER_NAME="`upsc ${DDL_DEVICE_NAME} driver.name 2>/dev/null`"
DDL_NUT_VERSION="`upsc ${DDL_DEVICE_NAME} driver.version 2>/dev/null`"
# TODO: check if a similar file exists, to update Report nb
DDL_REPORT_NUMBER="01"
DDL_FILENAME="${DDL_MFR}__${DDL_MODEL}__${DDL_DRIVER_NAME}__${DDL_NUT_VERSION}__${DDL_REPORT_NUMBER}.dev"
# Dump device data into the file
2022-07-10 10:23:45 +03:00
echo "# Device dump generated by $0 on $dumpDate" > ${DDL_FILENAME}
echo "# upsrw output:" >> ${DDL_FILENAME}
echo "${upsrwResult}" | sed -e 's/^/# /' >> ${DDL_FILENAME}
echo "# upscmd output:" >> ${DDL_FILENAME}
echo "${upscmdResult}" | sed -e 's/^/# /' >> ${DDL_FILENAME}
echo "" >> ${DDL_FILENAME}
echo "# upsc output:" >> ${DDL_FILENAME}
echo "${upscResult}" >> ${DDL_FILENAME}
2015-04-30 16:53:36 +03:00
echo "${DDL_FILENAME} generated using ${DDL_DEVICE_NAME} "