����Linux�Ż�
Linux����

����shell�ű����ۺϡ����С��鿴Linux Server������Ӳ����Ϣ

����ʱ��:2016-10-20 09:30:05��Դ:CSDN����:kai404
��Ϊ��ά��Ա���˽�ÿ̨��������Ӳ�������Ϣ�Լ�ϵͳ��������DZز����ٵĹ�������Ȼ���ѣ�ȴ����ɢ����Ϣ���жȲ��ߡ��ʶ���������һ�׼���չʾ������Ϣ��“ƽ̨”����ʵ̸����ƽ̨���ռ�-����-չʾ���ѣ�����ԭ����һ̨“��ػ�”��������ô�аɣ��������ű������ݼ�¼������IP���ļ�ѭ������ÿ̨server�����“����ػ�”�ϵ�����awk�ļ���awk���򣩣�����Ϣͳһ�ռ���“��ػ�”Ȼ����web server����չʾ���������������ͼ����
 
ע��web server�迪��Ŀ¼���ʹ���
 
��ҳҳ�棬���еķ�����������һ��Ŀ¼����ʽ��ʾ��Ŀ¼�ڰ�����server�����Ϣ
����shell�ű����ۺϡ����С��鿴Linux Server������Ӳ����Ϣ
 
ѡ��ij̨server�󣬽������ҳ�棬�ֱ��¼������ƻ�/Ӳ����Ϣ/����ǽ����/root-shellΪ����ϰ�ߴ��shell�ű���Ŀ¼/sys_confΪϵͳ���������ļ�
����shell�ű����ۺϡ����С��鿴Linux Server������Ӳ����Ϣ
 
���У�devinfo.txtΪ�����������Ӳ����Ϣ������ͼ�����˸о�“�ڴ�”����ʾЧ�����ұȽϵ���ģ���������Ŀ������ж��ٲ�ۡ����˼����������ڴ�ĵ�������/Ƶ��/���Ҵ��ţ���Щ��Ϣ�����ӻ��߸����ڴ��ʱ���Ƿdz����õġ����������Ϣ��lsblk����Ҳ�����ֱ��
����shell�ű����ۺϡ����С��鿴Linux Server������Ӳ����Ϣ
 
sys_confĿ¼�£�����������������ϵͳ���������ļ������������ļ�
����shell�ű����ۺϡ����С��鿴Linux Server������Ӳ����Ϣ
 
���������������е��õ�ͬѧ���Խ������¿����ʵ���ˡ����׽ű���CentOS6��7�϶��������
 
�ҵ�“��ػ�”����������ͨ��ssh����Կ��ʽ���Եǵ����ϸ�̨server����Ϊ�ⲻ��Ҫ�����϶�̨server�������������������б�Ҫ����������һ̨������Կ��¼����server�ģ���
 
���ű���“��ػ�”��ʱ���У�ͨ��ips.txt�ļ���ȡ������server����������IP��ips.txt��ͨ��������ʽͳ�ƶ���������Ͷ��ֶ�������þ����ֶ��༭�������ʽ���£�web1-x.x.x.x��ÿ��һ̨�����ű�ͬ��Զ��ִ�������ȡ��Ӧ��Ϣ��������Ҫ�ڸ�̨“����ػ�”�Ϸ�������awk�ļ�servername.awk��mem.awk��ͨ��awk -f ���ã����ڻ�ȡ����ʽ�����“�����ͺ� ����”��“�ڴ�”��Ϣ����������ν������ļ������ϴ��������������ڱ������۷�Χ��
 
���ս�������Ϣ��������“��ػ�”��/server_infoĿ¼�£���web server��Ŀ¼ָ�����ɡ�
 
���ű����ݣ�cat /root/shells/serverinfo.sh
#!/bin/sh
# by ljk
#ͨ������̨server��Ӳ����Ϣ�����ı���Ȼ��ͨ��web-server������ʾ
for server_ip in `cat /root/shells/ips.txt` #��¼����������������ip��������
do
ip=`echo $server_ip|awk -F '-' '{print $2}'`   #��ȡ��server IP
###��һ�����иýű������������Զ��������ټ�һ��yum -y install dmidecode util-linux-ng > /dev/null
###�Է��������
ssh root@$ip "cat /etc/issue|sed -n '1p' > /devinfo/devinfo.txt;
uname -a|cut -d ' ' -f 2|sed s/^/HostName:' '/ >> /devinfo/devinfo.txt;
uname -a|cut -d ' ' -f 3|sed s/^/Kernel:' '/ >> /devinfo/devinfo.txt;
dmidecode -t system|awk -f /root/shells/servername.awk >> /devinfo/devinfo.txt;
echo -e '\n--------CPU:-------' >> /devinfo/devinfo.txt;
lscpu |egrep -v 'Order|Vendor|Model|Stepping|BogoMIPS|family|On-line|op-mode|CPU\ socket|NUMA\ node0' >> /devinfo/devinfo.txt;
echo -e '\n------�ڴ�:------' >> /devinfo/devinfo.txt;
dmidecode -t memory|grep -A7 Physical >> /devinfo/devinfo.txt;
dmidecode -t memory|grep -e "Size.*[0-9]" -A8|awk -f /root/shells/mem.awk >> /devinfo/devinfo.txt;
echo -e '\n-------����:-------' >> /devinfo/devinfo.txt;
lsblk >> /devinfo/devinfo.txt;
crontab -l > /devinfo/crontab.txt;
iptables -L -n > /devinfo/iptables.txt"
mkdir /server_info/$server_ip &> /dev/null
scp root@$ip:/devinfo/* /server_info/$server_ip/
###��/tmp/$ip �¿���ϵͳ�������ļ� ��������
time=`date +%F`
mkdir -p /server_info/$server_ip/sys_conf/$time
cp  /tmp/$ip/* /server_info/$server_ip/sys_conf/$time/
###���������sys_conf����
find /server_info/$server_ip/sys_conf -type d -mtime +1|xargs rm -rf
###��������server/root/shells �µĽű�ͬ��������
rsync -av --delete root@$ip:/root/shells/ /server_info/$server_ip/root-shells
echo -e "\e[1;31m $server_ip is done \e[0m"  
done
 
���ű������õ�����awk�ļ���������
[root@web1 ~]# cat shells/servername.awk 
$0~ /Product.*/ {printf "%s","\nserver�ͺ�: "$(NF-1)" "$NF}
$0~ /Serial.*/ {printf "%s",$0"\n"}
[root@web1 ~]# cat shells/mem.awk 
$0~ /Size.*[0-9]/ {printf "%s",$0"\t"} 
$0~ /Speed.*[0-9]/ {printf "%s",$0"\t\t"} 
$0~ /Manufacturer.*/ {print "���Ҵ���: "$2}
 
ϣ�����׽ű��ܸ�����ͬѧ����Щ���İ�����Ҳ�����˿�Դ�ľ���
 
��ʵ��ֻ�DZ���“����ά��”��˼���һ��С���֣�����Сƽ̨�ɶ������ڣ�Ҳ��������ƽ̨�������������������ھ�����һ����˾�ڲ�����άƽ̨���������ޣ��Ƚϼ�ª����~�������ճ���Dev��test���������ߡ���־����ƽ̨���Լ����ķ��������server_infoƽ̨������һ��
 
�������ø��µ�ַ��//m.ajphoenix.com/linux/25198.html