Monitoring Linux Memory Usage Linux Script
ubuntu@server3:~$ cat memoryusage.sh
#!/bin/bash
#
# Author:ITM
# Script that tracks the current date, memory usage and running processes
#
echo '#!/bin/bash' > /root/memmon.sh
echo "
date;
uptime
free -m
vmstat 1 5
ps auxf --width=200
" >> /root/memoryusage.sh
chmod +x /root/memoryusage.sh
# create a cronjob that runs every few minutes to log the memory usage
echo '0-59/10 * * * * root /root/memoryusage.sh >> /root/memoryusage.txt' > /etc/cron.d/memoryusage
# restart crond
/etc/init.d/cron* restart
# create a logrotate entry so the log file does not get too large
echo '/root/memoryusage.txt {}' > /etc/logrotate.d/memoryusage
|