Browse Source

Fixed issue with CentOS not supporting free -h

pull/276/head
Daniel Gibbs 10 years ago
parent
commit
6fbf4fd765
  1. 39
      functions/fn_distrodetails

39
functions/fn_distrodetails

@ -7,8 +7,8 @@
# Description: Variables providing useful info on the Operating System such as disk and performace info. # Description: Variables providing useful info on the Operating System such as disk and performace info.
# Used for fn_details, fn_debugserver and fn_emailnotification. # Used for fn_details, fn_debugserver and fn_emailnotification.
# Distro infomation ## Distro infomation
# Returns architecture, kernel and distro/os # Returns architecture, kernel and distro/os.
arch=$(uname -m) arch=$(uname -m)
kernel=$(uname -r) kernel=$(uname -r)
if [ -f /etc/lsb-release ]; then if [ -f /etc/lsb-release ]; then
@ -33,18 +33,25 @@ else
tmuxv=$(tmux -V) tmuxv=$(tmux -V)
fi fi
# Performance ## Performance
# Average server load # Average server load
load=$(uptime|awk -F 'load average: ' '{ print $2 }') load=$(uptime|awk -F 'load average: ' '{ print $2 }')
# Memory # Memory
physmemtotal=$(free -h|grep "Mem:" | awk '{print $2}')
physmemused=$(free -h|grep "Mem:" | awk '{print $3}') # Older versions of free do not support -h option.
physmemfree=$(free -h|grep "Mem:" | awk '{print $4}') if [ "$(free -h > /dev/null 2>&1; echo $?)" -ne "0" ]; then
swaptotal=$(free -h|grep "Swap:" | awk '{print $2}') option="-m"
swapused=$(free -h|grep "Swap:" | awk '{print $3}') else
swapfree=$(free -h|grep "Swap:" | awk '{print $4}') option="-h"
fi
physmemtotal=$(free ${option} | grep "Mem:" | awk '{print $2}')
physmemused=$(free ${option} | grep "Mem:" | awk '{print $3}')
physmemfree=$(free ${option} | grep "Mem:" | awk '{print $4}')
swaptotal=$(free ${option} | grep "Swap:" | awk '{print $2}')
swapused=$(free ${option} | grep "Swap:" | awk '{print $3}')
swapfree=$(free ${option} | grep "Swap:" | awk '{print $4}')
# Uptime # Uptime
uptime=$(</proc/uptime) uptime=$(</proc/uptime)
@ -54,9 +61,9 @@ hours=$(( uptime/60/60%24 ))
days=$(( uptime/60/60/24 )) days=$(( uptime/60/60/24 ))
# Disk usage # Disk usage
# available space on the partition # available space on the partition.
availspace=$(df -hP ${rootdir} | grep -v "Filesystem" | awk '{print $4}') availspace=$(df -hP ${rootdir} | grep -v "Filesystem" | awk '{print $4}')
# used space in serverfiles dir # used space in serverfiles dir.
serverfilesdu=$(du -sh ${serverfiles} | awk '{print $1}') serverfilesdu=$(du -sh ${serverfiles} | awk '{print $1}')
if [ -z ${serverfilesdu} ]; then if [ -z ${serverfilesdu} ]; then
serverfilesdu="0M" serverfilesdu="0M"
@ -64,18 +71,18 @@ fi
# Backup info # Backup info
if [ -d "${backupdir}" ]; then if [ -d "${backupdir}" ]; then
# used space in backups dir # used space in backups dir.
backupdirdu=$(du -sh ${backupdir} | awk '{print $1}') backupdirdu=$(du -sh ${backupdir} | awk '{print $1}')
if [ -z ${backupdirdu} ]; then if [ -z ${backupdirdu} ]; then
backupdirdu="0M" backupdirdu="0M"
fi fi
# number of backups # number of backups.
backupcount=$(find "${backupdir}"/*.tar.gz | wc -l) backupcount=$(find "${backupdir}"/*.tar.gz | wc -l)
# most recent backup # most recent backup.
lastbackup=$(ls -t "${backupdir}"/*.tar.gz | head -1) lastbackup=$(ls -t "${backupdir}"/*.tar.gz | head -1)
# date of most recent backup # date of most recent backup.
lastbackupdate=$(date -r ${lastbackup}) lastbackupdate=$(date -r ${lastbackup})
# size of most recent backup # size of most recent backup.
lastbackupsize=$(du -h "${lastbackup}" | awk '{print $1}') lastbackupsize=$(du -h "${lastbackup}" | awk '{print $1}')
fi fi
Loading…
Cancel
Save