1. Solaris physical memory usage
Script to get free/unused memory on Solaris can be found with command vmstat. Without options, vmstat displays a one-line summary of the virtual memory activity since the system was booted. Tested on Solaris 5.8, 5.9, 5.10. Can be wrong on Zones.
Script ./mem_usage.sh
#!/bin/sh
mem_free=`vmstat 1 2 | tail -1 | awk '{print $5}' | tail -1`;
mem_free_in_mb=`echo $mem_free/1024 | bc`;
mem_total_in_mb=`/usr/sbin/prtconf 2>/dev/null | grep Memory | awk '{ print $3 }'`;
mem_usage_in_mb=`echo "$mem_total_in_mb-$mem_free_in_mb" | bc`;
mem_usage_in_per=`echo "$mem_usage_in_mb/($mem_total_in_mb/100)" | bc`;
echo "\tPhysical memory size:\t\t $mem_total_in_mb";
echo "\tMemory usage in MB:\t\t $mem_usage_in_mb";
echo "\tMemory usage in %:\t\t $mem_usage_in_per%";
Output:
# ./mem_usage.sh
Physical memory size: 768
Memory usage in MB: 633
Memory usage in %: 90%
2. Solaris swap usage
Script ./swap_usage.sh
#!/bin/sh
swap_total=`/usr/sbin/swap -l | grep "/" | awk '{ sum+=$4} END {print sum}'`;
swap_free=`/usr/sbin/swap -l | grep "/" | awk '{ sum+=$5} END {print sum}'`;
swap_in_use_per=`echo "($swap_total-$swap_free) / ($swap_total/100)" | bc`;
echo "\tSwap in use:\t\t $swap_in_use_per%";
Output:
# ./swap_usage.sh
Swap in use: 27%
3. Determine If system is Solaris Zone
#!/bin/sh
if [ -f "/usr/sbin/zoneadm" ]; then
/usr/sbin/zoneadm list | grep global 1>/dev/null;
if [ "$?" -ne "0" ]; then
zone_num=`/usr/sbin/zoneadm list | wc -l | sed 's/ //g'`;
if [ "$zone_num" = "1" ]; then
zone_status="Zone";
fi;
fi;
fi;
echo "\tSystem is:\t\t $zone_status";
4. Check RAID status metastatus and ZFS
#!/bin/sh
if [ -f "/usr/sbin/metastat" ]; then
metastatus_ok=`/usr/sbin/metastat 2>/dev/null | grep "State:" | wc -l|sed 's/ //g'`;
metastatus_err=`/usr/sbin/metastat 2>/dev/null | grep "State:" | grep -v "State: Okay" | wc -l|sed 's/ //g'`;
if [ "$metastatus_ok" = "0" ] && [ "$metastatus_err" = "0" ]; then
raid_status="no_meta_raids";
fi
if [ "$metastatus_ok" != "0" ] && [ "$metastatus_err" = "0" ]; then
raid_status="OK";
fi;
if [ "$metastatus_err" != "0" ]; then
raid_status="metastat_Failed";
fi;
raid_controller="Software RAID (metastatus)";
else
raid_status="no_metastatus";
fi;
if [ -f "/usr/sbin/zpool" ]; then
zfs_exists="ZFS"
zfs_pools=`/usr/sbin/zpool status -v`;
zfs_failed=`/usr/sbin/zpool status -v | grep "state:" | grep -v "ONLINE" | wc -l |sed 's/ //g'`;
if [ "$zfs_pools" = "no pools available" ]; then
zfs_status="no_zfs_pools";
else
if [ "$zfs_failed" != "0" ]; then
zfs_status="ZFS_Failed";
else
zfs_status="OK";
fi;
fi;
else
zfs_status="no_zfs";
fi;
echo "\tRAID Controller:\t $raid_controller, $zfs_exists";
echo "\tRAID Status:\t\t $raid_status, $zfs_status";
5. Get serial number on Solaris
#!/bin/sh
if [ -f "/usr/sbin/sneep" ]; then
serial=`/usr/sbin/sneep`;
else
serial=`/usr/sbin/eeprom | grep serial | awk -F= '{ print $2}'`;
fi;
echo "\tSerial:\t\t\t $serial";
6. Get Solaris OS name, version, update level
#!/bin/sh
os_name="`uname -s`";
os_ver="`uname -r`";
if head -1 /etc/release | grep u1 1>/dev/null ; then update_ver="U1"; fi;
if head -1 /etc/release | grep u2 1>/dev/null ; then update_ver="U2"; fi;
if head -1 /etc/release | grep u3 1>/dev/null ; then update_ver="U3"; fi;
if head -1 /etc/release | grep u4 1>/dev/null ; then update_ver="U4"; fi;
if head -1 /etc/release | grep u5 1>/dev/null ; then update_ver="U5"; fi;
if head -1 /etc/release | grep u6 1>/dev/null ; then update_ver="U6"; fi;
if head -1 /etc/release | grep u7 1>/dev/null ; then update_ver="U7"; fi;
if head -1 /etc/release | grep u8 1>/dev/null ; then update_ver="U8"; fi;
if head -1 /etc/release | grep u9 1>/dev/null ; then update_ver="U9"; fi;
if head -1 /etc/release | grep u10 1>/dev/null ; then update_ver="U10"; fi;
if head -1 /etc/release | grep s9_58shwpl3 1>/dev/null ; then update_ver="FCS"; fi;
echo "5CtOS version:\t\t $os_name $os_ver $update_ver";
7. Other
Vendor
#!/bin/sh
vendor=`/usr/sbin/prtconf 2>/dev/null | head -1 | awk '{print $3 " " $4}'`;
echo "\tVendor:\t\t\t $vendor";
Hardware
#!/bin/sh
hw="`uname -i`";
echo "\tHardware:\t\t\t $hw";
Platform 32/64bit
#!/bin/sh
os_bit="`isainfo -kv | awk '{print $1}'`";
echo "\tPlatform:\t\t $os_bit";
NTP stratums
#!/bin/sh
ntp_stratum=`/usr/sbin/ntpq -p 2>/dev/null | awk '{ print $3 }'| tail +3`
ntp_status=`echo $ntp_stratum`;
echo "\tNTP:\t\t\t $ntp_status";
All IP addresses
#!/bin/sh
ip_all="`/sbin/ifconfig -a | grep inet | grep -v 127.0.0.1 | awk '{print $2}'`";
ip_all_one_string="`echo $ip_all`";
echo "\tIP all:\t\t\t $ip_all_one_string";
Root files system usage
#!/bin/sh
fs_root="`df -k | grep "/$" | awk '{print $5}'`";
echo "\tFS ROOT:\t\t $fs_root";
All files systems usage
#!/bin/sh
fs_all=`df -k | grep "/" | grep -v "/$" | grep -v "/proc" | grep -v "/etc/mnttab" | grep -v "/etc/dfs/sharetab" | grep -v "/lib/libc.so.1" | awk '{print $6 " " $5 ","}'`
fs_all_one_string="`echo $fs_all`";
echo "\tFS ALL:\t\t\t $fs_all_one_string";