2008-09-16 17:19:14 +02:00
|
|
|
#!/bin/bash
|
2009-11-08 02:38:04 +01:00
|
|
|
# Generic SSH Exec Pandora FMS Server plugin
|
|
|
|
# (c) Sancho Lerena 2008-2009
|
2008-09-16 17:19:14 +02:00
|
|
|
|
2009-11-08 02:38:04 +01:00
|
|
|
# Default values
|
2009-11-19 14:40:42 +01:00
|
|
|
USER="root"
|
2009-11-08 02:38:04 +01:00
|
|
|
HOST=""
|
|
|
|
COMMAND=""
|
|
|
|
PORT=22
|
2008-09-16 17:19:14 +02:00
|
|
|
|
2009-11-08 02:38:04 +01:00
|
|
|
function help {
|
|
|
|
echo -e "Generic SSH Execution plugion for Pandora FMS Plugin server. http://pandorafms.com"
|
|
|
|
echo -e "Syntax:"
|
|
|
|
echo -e "\t\t-u user"
|
|
|
|
echo -e "\t\t-p SSH port (by default 22)"
|
|
|
|
echo -e "\t\t-t Hostname / Target IP Address"
|
|
|
|
echo -e "\t\t-c Commnand"
|
|
|
|
echo -e "Samples:"
|
|
|
|
echo " ./ssh_pandoraplugin.sh -t 192.168.5.20 -u root -c \"ls -la /etc/myfile.conf | wc -l\""
|
|
|
|
echo ""
|
|
|
|
echo -e "Please note that before use this plugin you need to export user publickey of "
|
|
|
|
echo -e "Pandora running user on the server destination of the command, and make the host"
|
|
|
|
echo -e "key autenthication first"
|
|
|
|
exit
|
|
|
|
}
|
|
|
|
|
|
|
|
if [ $# -eq 0 ]
|
|
|
|
then
|
|
|
|
help
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# Main parsing code
|
|
|
|
|
|
|
|
while getopts ":hp:t:c:u:" optname
|
|
|
|
do
|
|
|
|
case "$optname" in
|
|
|
|
"h")
|
|
|
|
help
|
|
|
|
;;
|
|
|
|
"u")
|
2009-11-19 14:40:42 +01:00
|
|
|
USER=$OPTARG
|
2009-11-08 02:38:04 +01:00
|
|
|
;;
|
|
|
|
"t")
|
|
|
|
HOST=$OPTARG
|
|
|
|
;;
|
|
|
|
"c")
|
|
|
|
COMMAND=$OPTARG
|
|
|
|
;;
|
|
|
|
"p")
|
|
|
|
PORT=$OPTARG
|
|
|
|
;;
|
|
|
|
?)
|
|
|
|
help
|
|
|
|
;;
|
|
|
|
default)
|
|
|
|
help
|
|
|
|
;;
|
|
|
|
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
|
2013-06-26 18:21:36 +02:00
|
|
|
ssh -p $PORT $USER@$HOST $COMMAND 2> /dev/null
|
|
|
|
|