first commit
This commit is contained in:
50
OpenShift Stuff/run_collect_info.sh
Normal file
50
OpenShift Stuff/run_collect_info.sh
Normal file
@ -0,0 +1,50 @@
|
||||
#!/bin/bash
|
||||
#Roy Cohen :roy@wondercohen.nl :
|
||||
#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/*
|
||||
|
||||
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")
|
||||
if [[ $SSH_OUT == "please install the bc command" ]]
|
||||
then
|
||||
echo "please install the bc command on $HOST" && exit 1
|
||||
else
|
||||
printf "%s " "$HOST," >> results/$CONTRACT_LIST
|
||||
echo $SSH_OUT >> results/$CONTRACT_LIST
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
# sun-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
|
Reference in New Issue
Block a user