Skip to content

Instantly share code, notes, and snippets.

@richardsonlima
Last active June 16, 2016 21:49
Show Gist options
  • Save richardsonlima/46e28e05b6984877976ad4e159f77f52 to your computer and use it in GitHub Desktop.
Save richardsonlima/46e28e05b6984877976ad4e159f77f52 to your computer and use it in GitHub Desktop.
# SCRIPT 01
root@Zabbix:/home/zabbix/scripts# cat deploy-choco.sh
#!/bin/bash
# This script detects the OS on a target machine and deploys the corresponding zabbix agent on Windows, Linux or Solaris
export LOG; LOG=/home/zabbix/scripts/logs/deploy.log
export DATE; DATE=`date +%F,%H:%M`
if [[ $# -lt 1 ]]
then echo "Usage: $0 Hostname|IP"
exit 1
fi
# Check if machine is online
/bin/ping -c1 $1 > /dev/null
if [[ $? != 0 ]]
then echo "Machine is not online!!! Please power on machine first!!!"
exit 1
fi
# Determine OS
#OS=`/usr/bin/nmap -O $1 | awk -F : '/OS details:/ {printf $2}'`
OS=`/usr/bin/nmap -O --osscan-guess $1 | awk -F : '/Running/ {printf $2}'`
case $OS in
*Linux*)
OS="Linux"
echo "Detected $OS Operating System on $1" | tee -a $LOG
echo "not implemented yet"
#/home/zabbix/scripts/deploy_zabbag_linux.sh $1
;;
*Solaris*)
OS="Solaris"
echo "Detected $OS Operating System on $1" | tee -a $LOG
echo "not implemented yet"
#/home/zabbix/scripts/deploy_zabbag_solaris.sh $1
;;
*Windows*)
OS="Windows"
echo " $DATE Detected $OS Operating System on $1" | tee -a $LOG
/home/zabbix/scripts/win-deploy-choco.sh $1
;;
*)
echo "ERROR: Your operating system $OS is not supported by this script!!!"
;;
esac
# SCRIPT 02
root@Zabbix:/home/zabbix/scripts# cat /home/zabbix/scripts/win-deploy-choco.sh
HOST=$1
if [[ $# -lt 1 ]]
then echo "Usage: $0 Hostname"
exit 1
fi
/bin/ping -c1 $HOST > /dev/null
if [[ $HOST = 1 ]]
then echo "Machine is not online!!! Please power on machine first!!!"
exit 1
fi
winexe --user administrator%'PASSWORD' -W WORKGROUP //$HOST 'cmd /c "mkdir c:\Choco & cd c:\Choco & copy "\\192.168.0.2\zabbix-agents\zabbix_agents_v2\installChoco.cmd" "c:\Choco" & installChoco.cmd "'
# FILE - installChoco.cmd
@echo off
SET DIR=%~dp0%
::download install.ps1
%systemroot%\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "((new-object net.webclient).DownloadFile('https://chocolatey.org/install.ps1','install.ps1'))"
::run installer
%systemroot%\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "& '%DIR%install.ps1' %*"
### TRICK TO INSTALL winexe with deb file =D ####
wget http://download.opensuse.org/repositories/home:/uibmz:/opsi:/opsi40-testing/xUbuntu_12.04/amd64/winexe_1.00.1-1_amd64.deb
sudo dpkg --install winexe_1.00.1-1_amd64.deb
### TRICK ###
for server in $(seq 255) ; do echo -e '\033[0;36m [+] Checagem para instalacao do Choco em: \033[m' 192.168.0.$server && ./deploy-choco.sh 192.168.0.$server;done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment