Hi All ,
Need one help,
I have created a script that will fetch remote server details i.e hostname , CPU count , memory and server space and and i get the output in csv format but the problem is that its not in correct format i,e i want the out like under host hotsname should come and CPU cpu number should come.
please find the script and the output of the script.
Need urgent help on this..... thanks in advance .
Script
export DATE=`date +%d%h%y_%T`
login_id=rnawale
host_name=""
file_name="serverlist.txt"
DEST=/U01/rnawale/remotedetail.csv
for i in $(cat $file_name);
do
hostname=$(echo $i| cut -f1 -d',')
# Below command will connect to remote server and fetch CPU cpunt.
A=`sshpass -p '******' ssh -o StrictHostKeyChecking=no $login_id@$hostname " hostname -f"`
B=`sshpass -p '******' ssh -o StrictHostKeyChecking=no $login_id@$hostname "cat /proc/cpuinfo | grep processor | awk '{a++} END {print a}'"`
# Below command will get the total memory on the remote server.
C=`sshpass -p '******' ssh -o StrictHostKeyChecking=no $login_id@$hostname "free -g | sed -n -e '/^Mem:/s/^[^0-9]*\([0-9]*\) .*/\1/p' "`
# Below command will give server space details
D=`sshpass -p '******' ssh -o StrictHostKeyChecking=no $login_id@$hostname "df -hP -x nfs |grep -vE '^Filesystem' | awk '{ print $5 " " $6 }'|sed 's/%//g'"`
# Below command will give server FQDN
echo -e "Host:- ${i}" "Hostname(FQDN):- $A " "CPU Count:- $B" "Total Memory:- $C" "Server Space:- \n $D\n" >> ${DEST}
#echo -e "Host:- ${i}" "Hostname(FQDN):- $A " "CPU Count:- $B" "Total Memory:- $C" "Server Space:- \n $D\n" awk -F ":" '{print NR,NF}' ${DEST}
#echo -e "Host:- ${i}" >> ${DEST}
#echo -e "Hostname(FQDN):- $A " >> ${DEST}
#echo -e "CPU Count:- $B" >> ${DEST}
#echo -e "Total Memory:- $C" >> ${DEST}
#echo -e "Server Space:- \n $D\n" >> ${DEST}
done
#mail -s '" Servers Detail Testing script"' </U01/ofssobp/output.log rajesh.nawale@abc.com
echo "Please find the attached Remote Server information " | mutt -a "$DEST" -s "Remote server Information " -- rajesh.nawale@abc.com
OUTPUT
Host:- 10.180.1.3 Hostname(FQDN):- abc310422.in.oracle.com CPU Count:- 2 Total Memory:- 11 Server Space:-
/dev/xvda2 172G 31G 133G 19 /
/dev/xvda1 996M 136M 809M 15 /boot
tmpfs 12G 0 12G 0 /dev/shm
Host:- 10.180.1.2 Hostname(FQDN):- abc310431.in.oracle.com CPU Count:- 4 Total Memory:- 15 Server Space:-
/dev/xvda2 220G 56G 153G 27 /
/dev/xvda1 996M 136M 809M 15 /boot
tmpfs 16G 0 16G 0 /dev/shm
Host:- 10.180.1.1 Hostname(FQDN):- abc310562.in.oracle.com CPU Count:- 4 Total Memory:- 15 Server Space:-
/dev/xvda2 220G 23G 186G 11 /
/dev/xvda1 996M 136M 809M 15 /boot
tmpfs 16G 0 16G 0 /dev/shm
~
~