casartist.blogg.se

Shell script to monitor cpu and memory usage in linux
Shell script to monitor cpu and memory usage in linux









We have taken care of formatting the output (to certain extent). Here we have written a shell Script that do not aims to automate the task of a typical system admin, but it may be helpful at places and specially for those newbies who can get most of the information they require about their System, Network, Users, Load, Ram, host, Internal IP, External IP, Uptime, etc. For the most repetitive task most of the administrator write a script to automate their day-to-day repetitive task. These shell scripts can help you to monitor and prevent your system from becoming unresponsive due to disk space issues.įeel free to leave a comment if you have any questions.The duty of System Administrator is really tough as he/she has to monitor the servers, users, logs, create backup and blah blah blah. */10 * * * * /bin/bash /opt/script/disk-usage-alert-2.sh Conclusion Sample email alert: The partition /dev/mapper/vg_2g-lv_dbs on 2g.CentOS6 has used 82% at Wed Feb 24 06:16:Īdd a cronjob to automate this. # vi /opt/script/disk-usage-alert.shĭusage=$(df -Ph | grep -vE '^tmpfs|cdrom' | sed s/%//g | awk ')Įcho "The Mount Point "/DB" on $(hostname) has used $used at $(date)" | mail -s "Disk space alert on $(hostname): $used used" Be sure to include your email ID in the script. In this example, we set threshold at 60% for testing purpose and you can change this limit based on your requirements. This script is very simple and straightforward, which triggers an email when the system reaches a given threshold. 9.8G Method-1: Shell script to monitor disk space usage in Linux

shell script to monitor cpu and memory usage in linux

Test-script.sh: line 7: [: /dev/mapper/vg_2g-lv_root: integer expression expected Use “df -Ph” (POSIX output format) to deal with this problem. Make a note: When using “df -h” in the shell script in some distributions, you may end up with the below error message as the output is not in the correct format. Refer to this article (embedded link), If you are looking for a bash script to monitor disk space usage on multiple remote Linux systems. These scripts will trigger an email to the corresponding email id when the system reaches a given threshold.

shell script to monitor cpu and memory usage in linux

We have included three shell scripts below and you can choose the one that suits your need. In this case, it is better to write a shell script based on what you need to monitor in your environment. However, it is suitable for small and large environments, but what is the best approach if you only have a few systems?

shell script to monitor cpu and memory usage in linux

There are various monitoring tools available that monitor everything, and trigger an email when the system reaches a given threshold.

shell script to monitor cpu and memory usage in linux

It is an important task for Linux administrators to monitor disk space usage on any system that’s used for hosting critical applications, in order to prevents the system from becoming unresponsive or get into an unknown problem.











Shell script to monitor cpu and memory usage in linux