System Monitoring With Shell Script In Linux

Specification

With all the flexibilities provided by the Linux systems, there are numerous issues that arouses due to the open source nature of the operating system. Even though most of the distributions of Linux are bundled with lots of performance monitoring tools. All these command line and GUI based tools offers different metrics that can be utilized to collect information about system and user activities.

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper

System administrators can utilize all these tools in order to find out the possible reasons of any kind of performance issues for any kind of Linux distributions. The following report contributes the development of a shell script that uses the most fundamental commands to system performance analysis and other debugging issues.

Specification

The shell script for this project is developed using the Vim Text editor and Bash shell on the Ubuntu distribution of Linux. All the commands that are compatible with different distributions of the Linux operating system is included and managed in the script. Being the best practice the terminal in the Ubuntu is used for development and testing of the script.

Using the terminal, we changed the permission of the script to be a executable using the chmod +x mySysMonitor.sh is used. Apart from this the terminal is used checking devices, status and usage, files permission as well as folders of the file systems. As it is important to generate a log file in html format thus using the ./mySysMonitor.sh to execute the script and store the file in the directories.

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper

Design consideration

 Following are the code to of the developed script that generates the HTML report of the Linux System monitoring activities.

usbdev_name=`lsusb`

upt=`ip link show`

ip_add=`ifconfig | grep “inet addr” | head -2 | tail -1 | awk {‘print$2’} | cut -f2 -d:`

num_proc=`ps -ef | wc -l`

total_root_size=`df -h /dev/sda1 | tail -1 | awk ‘{print$2}’`

load_avg=`cat /proc/loadavg  | awk {‘print$1,$2,$3’}`

disk_usage=`df -h /boot| awk {‘print $5,$6’}`

ram_total=`free -m | head -2 | tail -1 | awk {‘print$2’}`

prcs=`ps`

user=`who`

if [ ! -d ${HOME}/mySysMonitorlog ]

then

  mkdir ${HOME}/mySysMonitorlog

fi

html=”${HOME}/health_reports/mySysMmonitor.log-“.html”

for i in `ls /home`; do sudo du -sh /home/$i/* | sort -nr | grep G; done > /tmp/dir.txt

echo “<html>” >> $html

echo “<body>” >> $html

echo “<fieldset>” >> $html

echo “<center>” >> $html

echo “<h2>Linux system monitoring Report” >> $html

echo “</center>” >> $html

echo “</fieldset>” >> $html

echo “<br>” >> $html

echo “<center>” >> $html

Design Considerations

echo “<h2>Report Details : </h2>” >> $html

echo “<table class=”pure-table”>” >> $html

echo “<thead>” >> $html

echo “<tr>” >> $html

echo “<th>usb devices</th>” >> $html

echo “<th>user</th>” >> $html

echo “<th>IP Address of the system</th>” >> $html

echo “<th>network interfaces</th>” >> $html

echo “</tr>” >> $html

echo “</thead>” >> $html

echo “<tbody>” >> $html

echo “<tr>” >> $html

echo “<td>$usbdev_name</td>” >> $html

echo “<td>$user</td>” >> $html

echo “<td>$ip_add</td>” >> $html

echo “<td>$upt</td>” >> $html

echo “</tr>” >> $html

echo “</tbody>” >> $html

echo “</table>” >> $html

echo “<h2>Resources: </h2>” >> $html

echo “<br>” >> $html

echo “<table class=”pure-table”>” >> $html

echo “<thead>” >> $html

echo “<tr>” >> $html

echo “<th># of Processes</th>” >> $html

echo “<th>Total Size of Root FS</th>” >> $html

echo “<th>Load Average</th>” >> $html

echo “<th>Disk usgae</th>” >> $html

echo “<th> RAM</th>” >> $html

echo “<th>Current Processes</th>” >> $html

echo “</tr>” >> $html

echo “</thead>” >> $html

echo “<tbody>” >> $html

echo “<tr>” >> $html

echo “<td><center>$num_proc</center></td>” >> $html

echo “<td><center>$load_avg</center></td>” >> $html

echo “<td><center>$disk_usage</center></td>” >> $html

echo “<td><center>$ram_total</center></td>” >> $html

echo “<td><center>$prcs</center></td>” >> $html

echo “</tr>” >> $html

echo “</tbody>” >> $html

echo “</table>” >> $html

echo “<h2>other  Directories </h2>” >> $html

echo “<br>” >> $html

echo “<table class=”pure-table”>” >> $html

echo “<thead>” >> $html

echo “<tr>” >> $html

echo “<th>Size</th>” >> $html

echo “<th>Name</th>” >> $html

echo “</tr>” >> $html

echo “</thead>” >> $html

echo “<tr>” >> $html

while read size name;

do

  echo “<td>$size</td>” >> $html

  echo “<td>$name</td>” >> $html

  echo “</tr>” >> $html

  echo “</tbody>” >> $html

done < /tmp/dir.txt

echo “</table>” >> $html

echo “</body>” >> $html

echo “</html>” >> $html

echo “Report has been generated in ${HOME}/health_reports with file-name = $html.”

Extensive test result and screenshot

 The following is the screenshot, which depicts the use and installation of the mySysMonitor.sh script which asks the user to enter the sudo user password in order to generate and store the report.

 The above screen shot shows the html report browsed in the Mozilla browser which is available in the Ubuntu distributions of Linux. 

Conclusion

It is important to monitor the use of the resources by the different users and processes in order to maintain the consistent performance level of the system that is using the Linux distributions while addressing the issues of the system in an efficient way. The script is developed in such a way that, it will ask for “sudo” password before running and installing it on any system on bash script. So that only the system administrators will be able to access she results and control the system resource utilization. Even though the use of the sell script is time and memory consuming as for the execution of the script every time a new process is started from the Linux kernel.

Ebrahim, M. and Mallett, A., 2018. Mastering Linux Shell Scripting: A practical guide to Linux command-line, Bash scripting, and Shell programming.

Gantala, A., Vijaykumar, G., Telagam, N. and Anjaneyulu, P., 2017. Design of Smart Sensor Using Linux-2.6. 29 Kernel. International Journal of Applied Engineering Research, 12(18), pp.7891-7896.

Gantala, A., Vijaykumar, G., Telagam, N. and Anjaneyulu, P., 2017. Design of Smart Sensor Using Linux-2.6. 29 Kernel. International Journal of Applied Engineering Research, 12(18), pp.7891-7896.

Kraemer, J.A., CARBON BLACK Inc, 2017. System and Method for Reverse Command Shell Detection. U.S. Patent Application 15/457,719.

Wang, B., Lu, K. and Chang, P., 2016, August. Design and implementation of Linux firewall based on the frame of Netfilter/IPtable. In Computer Science & Education (ICCSE), 2016 11th International Conference on (pp. 949-953). IEEE.

Calculate your order
Pages (275 words)
Standard price: $0.00
Client Reviews
4.9
Sitejabber
4.6
Trustpilot
4.8
Our Guarantees
100% Confidentiality
Information about customers is confidential and never disclosed to third parties.
Original Writing
We complete all papers from scratch. You can get a plagiarism report.
Timely Delivery
No missed deadlines – 97% of assignments are completed in time.
Money Back
If you're confident that a writer didn't follow your order details, ask for a refund.

Calculate the price of your order

You will get a personal manager and a discount.
We'll send you the first draft for approval by at
Total price:
$0.00
Power up Your Academic Success with the
Team of Professionals. We’ve Got Your Back.
Power up Your Study Success with Experts We’ve Got Your Back.