quarta-feira, dezembro 24, 2014

CentOS – RedHat: A “systeminfo” like script for Linux | George's little internet notebook

CentOS – RedHat: A “systeminfo” like script for Linux | George's little internet notebook

System info, centos system info by email



CentOS – RedHat: A “systeminfo” like script for Linux

Windows has a nice command called “systeminfo” which provides a collection of general information for the Operating System. I created a Bash script that does something similar.
Note 1) this is part of a larger script I am creating which will import Operating System data into a Database.
Note 2) In order to view the network connection called in one of the functions in this script, you will have to be logged in as root to run this script. Unless of course you have setup sudo to run the “lsof” command.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/bin/bash
############################################
#This script is broken down into functions #
############################################
############################################
#Below all the functions are declared.
############################################
clear
function Operating_SystemVersion_info ()
{
V_Server_Name=`hostname`
V_OS_Version=`cat /etc/redhat-release`
echo "Host: $V_Server_Name  Version: $V_OS_Version";
echo "-"
}
 
function Memory_Usage()
{
Total_Memory=`free -m | grep 'Mem' | awk '{print $2}'`
Used_Memory=`free -m | grep 'Mem' | awk '{print $3}'`
Free_Memory=`free -m | awk 'FNR == 2 {print $4}'`
Swap_Size=`cat /proc/swaps | grep 'partition' | awk '{print $3}'`
Swap_Used_Space=`cat /proc/swaps | grep 'partition' | awk '{print $4}'`
Swap_info=`cat /proc/swaps | grep 'partition' | awk '{print "partition: " $1 " Priority " $5}'`
printf "MEMORY INFO\n"
printf "\t""\t""Total Memory $Total_Memory-MBs""\n"
printf "\t""\t""Used Memory $Used_Memory-MBs""\n"
printf "\t""\t""Free Memory $Free_Memory-MBs""\n"
printf "\t""\t""Used Swap $Swap_Used_Space-MBs""\n"
printf "\t""\t""Swap priority info $Swap_info""\n"
echo ""
}
 
function CPU_Load_Usage()
{
CPU_Cores=`cat /proc/cpuinfo | grep 'processor' | wc -l`
CPU_15min_Load=`uptime | awk '{print $10}'`
CPU_10min_Load=`uptime | awk '{pring $11}'`
CPU_15min_Load=`uptime | awk '{print $12}'`
}
 
function Storage_usage ()
{
printf "STORAGE INFO \n"
df -ah | awk '/%/ {print "\t""\t"$3 " " $4 " " $5 " " $6}'
echo ""
swap_size=`cat /proc/sys/vm/swappiness`
printf "\t""\t""Swap File usage: $swap_size""\t""\n"
printf "\t""\t""0 = OS is not using swap filesystem""\n"
printf "\t""\t""100 = OS is fully using swap filesystem""\n""\n"
}
 
function Top_output {
echo "RUNNING PROCESSES"
ps -auxe 2>/dev/null | awk '{print $1}' | sort | uniq -c
echo ""
}
 
function Network_Setup_Information ()
{
printf  "NET INTERFACES \n"
Links=`find /etc/sysconfig/network-scripts/ -name ifcfg-* -type f | xargs  grep 'IPADDR' | awk -F"/" '{print $5}' | awk '1;!(NR%1){print " ";}'`
echo $Links | tr ' ' '\n' > F_net_interfaces
for loop_interfaces in `cat F_net_interfaces`;
do
printf  "\t""\t""$loop_interfaces""\n";
done
echo ""
}
 
function Network_Activity_Information ()
{
touch F_port_scan
>F_port_scan
printf "NETWORK CONNECTIONS \n\n"
lsof -i -n -P | awk '/LISTEN/ {print "Service: " $1, "is listening on port: " $9}' | grep -v 127.0.0.1 | sort -u  >> F_port_scan
while read F_port_scan;
do
printf "\t""\t""$F_port_scan""\t""\n";
done < F_port_scan;
echo ""
}
function swappiness_Information ()
{
swap_size=`cat /proc/sys/vm/swappiness`
printf "\t""\t"0 = OS is not using swap filesystem"
printf "\t""\t"100 = OS is fully using swap filesystem"
printf "\t""\t""$swap_size""\t""\t"
}
Operating_SystemVersion_info;
Memory_Usage;
CPU_Load_Usage;
Storage_usage;
Top_output;
Network_Setup_Information;
Network_Activity_Information;
#---
#Checking to see if it s a virtual server or not.
printf "HYPERVISOR STATUS""\n""\n"
dmesg | grep -i '"Hypervisor detected: VMware"' >> /dev/null  2>&1
if [[ $? -eq 0 ]];
then
printf "\t""\t""This is a VMware Virtual Machine""\n"
else
printf "\t""\t""This is Physical Machine""\n"
fi
1
 
Share Button

Nenhum comentário: