DESCRIPTION:
Install sysstat and postfix before running the script
SCRIPT:
#!/bin/bash
#install below packeges befor running the script
#sudo apt-get install sysstat, sudo apt-get install postfix
SUB_CPU="CPU USAGE"
SUB_MEMORY="MEMORY USAGE"
TO=youradmin@anymail.com
CPU_LOG=/var/log/mylog
MEMORY_LOG=/tmp/mem_log
while ((1))
do
mpstat > $CPU_LOG
mail -s "$SUB_CPU" "$TO" < $CPU_LOG
sleep 2
cat $CPU_LOG
egrep --color 'Mem|Cache|Swap' /proc/meminfo > $MEMORY_LOG
mail -s "$SUB_MEMORY" "$TO" < $MEMORY_LOG
sleep 2
cat $MEMORY_LOG
sleep 60
done
OUTPUT:
sujin@sujin:~/sujin/work$ sudo ./test.sh
Linux 3.0.0-24-generic (sujin) 03/22/2013 _i686_ (4 CPU)
06:56:24 PM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %idle
06:56:24 PM all 6.58 0.01 1.32 0.93 0.00 0.01 0.00 0.00 91.15
MemTotal: 3526272 kB
MemFree: 1495584 kB
Cached: 1072248 kB
SwapCached: 0 kB
SwapTotal: 4098044 kB
SwapFree: 4098044 kB
Linux 3.0.0-24-generic (sujin) 03/22/2013 _i686_ (4 CPU)
06:57:28 PM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %idle
06:57:28 PM all 6.55 0.01 1.32 0.93 0.00 0.01 0.00 0.00 91.18
MemTotal: 3526272 kB
MemFree: 1508548 kB
Cached: 1054596 kB
SwapCached: 0 kB
SwapTotal: 4098044 kB
SwapFree: 4098044 kB
Install sysstat and postfix before running the script
SCRIPT:
#!/bin/bash
#install below packeges befor running the script
#sudo apt-get install sysstat, sudo apt-get install postfix
SUB_CPU="CPU USAGE"
SUB_MEMORY="MEMORY USAGE"
TO=youradmin@anymail.com
CPU_LOG=/var/log/mylog
MEMORY_LOG=/tmp/mem_log
while ((1))
do
mpstat > $CPU_LOG
mail -s "$SUB_CPU" "$TO" < $CPU_LOG
sleep 2
cat $CPU_LOG
egrep --color 'Mem|Cache|Swap' /proc/meminfo > $MEMORY_LOG
mail -s "$SUB_MEMORY" "$TO" < $MEMORY_LOG
sleep 2
cat $MEMORY_LOG
sleep 60
done
OUTPUT:
sujin@sujin:~/sujin/work$ sudo ./test.sh
Linux 3.0.0-24-generic (sujin) 03/22/2013 _i686_ (4 CPU)
06:56:24 PM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %idle
06:56:24 PM all 6.58 0.01 1.32 0.93 0.00 0.01 0.00 0.00 91.15
MemTotal: 3526272 kB
MemFree: 1495584 kB
Cached: 1072248 kB
SwapCached: 0 kB
SwapTotal: 4098044 kB
SwapFree: 4098044 kB
Linux 3.0.0-24-generic (sujin) 03/22/2013 _i686_ (4 CPU)
06:57:28 PM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %idle
06:57:28 PM all 6.55 0.01 1.32 0.93 0.00 0.01 0.00 0.00 91.18
MemTotal: 3526272 kB
MemFree: 1508548 kB
Cached: 1054596 kB
SwapCached: 0 kB
SwapTotal: 4098044 kB
SwapFree: 4098044 kB
No comments:
Post a Comment