first commit
This commit is contained in:
54
scripts/tools/run_collect_info_v2.sh
Normal file
54
scripts/tools/run_collect_info_v2.sh
Normal file
@ -0,0 +1,54 @@
|
||||
#!/bin/bash
|
||||
#Roy Cohen :roy@proteon.com
|
||||
#Proteon B.V. :Zuid Hollandlaan 7, 2596 AL Den Haag
|
||||
#objective :Script that scp's collect_info.sh from a host source file, and collects and sums-up Total Processors, Memory RAM Total Disk size contact code files.
|
||||
#First line of code :09/10/2019
|
||||
#last update :11/10/2019
|
||||
#version :0.1
|
||||
#synatx example of hostfile :<hostname,contract code> contract code must be in uppercase and my contain numbers
|
||||
|
||||
if [ $# -lt 1 ]
|
||||
then
|
||||
echo "Syntax: ./$(basename $0) <file name with hosts and contract codes>"
|
||||
exit
|
||||
fi
|
||||
CHECK_CONTACT_CODES=$(cat $1 |cut -d "," -f2| grep -oP '[a-z]'|wc -l)
|
||||
|
||||
if [[ $CHECK_CONTACT_CODES -gt 0 ]]
|
||||
then
|
||||
echo "there is some issue with the contact code in the hostfile, please make sure that all contact cods are in uppercase"
|
||||
|
||||
else
|
||||
#clean the results directory
|
||||
rm /opt/scripts/tools/collect_info/results/*
|
||||
|
||||
#collect data from remote server
|
||||
for host in $(cat $1)
|
||||
do
|
||||
HOST=$(echo $host|cut -d "," -f1)
|
||||
CONTRACT_LIST=$(echo $host|cut -d "," -f2)
|
||||
scp -q -p collect_info.sh $HOST:/root
|
||||
SSH_OUT=$(ssh -n $HOST "/root/collect_info.sh")
|
||||
printf "%s " "$HOST," >> results/$CONTRACT_LIST
|
||||
echo $SSH_OUT >> results/$CONTRACT_LIST
|
||||
done 2>/opt/scripts/tools/collect_info/results/error.log
|
||||
|
||||
|
||||
# sums-up the colleced data in to contact code files
|
||||
for contr_file in $(ls /opt/scripts/tools/collect_info/results/)
|
||||
do
|
||||
RAM=$(cat results/$contr_file|cut -d "," -f3| paste -sd+ | bc )
|
||||
CPU=$(cat results/$contr_file|cut -d "," -f5| paste -sd+ | bc )
|
||||
HDD=$(cat results/$contr_file|cut -d "," -f7| paste -sd+ | bc )
|
||||
echo "Total Processors, $CPU" > /opt/scripts/tools/collect_info/results/$contr_file
|
||||
echo "Memory RAM Total in MB, $RAM" >> /opt/scripts/tools/collect_info/results/$contr_file
|
||||
echo "Disk size in GB, $HDD" >> /opt/scripts/tools/collect_info/results/$contr_file
|
||||
done
|
||||
fi
|
||||
|
||||
#cat all the contracts
|
||||
for contr in $(ls /opt/scripts/tools/collect_info/results/)
|
||||
do
|
||||
echo "----$contr---"
|
||||
cat /opt/scripts/tools/collect_info/results/$contr
|
||||
done
|
Reference in New Issue
Block a user