Bash Script For Monitoring Linux Systems And Servers

              Its a simple Bash script to check, test and monitor basic system performance, services, resources, etc. With this Bash script, you can do the 11 tasks listed below. Also feel free to edit the script as needed.

  • View the hostname of the system
  • View system date and time
  • Check the free memory 
  • Check Hard disk free space
  • Check status of some regular services (you may need to edit the script to add your own services and daemons)
  • View system ip address information
  • Check internet connection by pinging to the domain "google.com"
  • Check the system uptime
  • List all the currently logged in users (including remote SSH logins)
  • Review system processes and CPU load
  • Schedule a shutdown
Creating Bash script
[root@server ~] vi basic_info
#Now add all the below text(green in colour) to the file 


#!/bin/bash
clear
menu=
time=
echo "=========== =========== ========="
echo "WELCOME TO MACHINE INFO SCRIPT"
echo "=========== =========== ========="
echo "1: View the hostname of this machine"
echo "2: View system date and time"
echo "3: Check free RAM space"
echo "4: Check Hard disk free space"
echo "5: Check status of regular services"
echo "6: View system ipaddress information"
echo "7: Check internet connection (ping to Google)"
echo "8: Check how long system is running"
echo "9: List the current logged in users information"
echo "10: Review system process and cpu"
echo "11: Schedule a shutdown"
echo "0: Exit from Script"
until [ "$menu" = "0" ]; do
echo -n "enter menu selection>"
read menu
if [ "$menu" = "0" ]; then
echo "Bye, Exiting Script...." $exit
fi
case $menu in
1 ) hostname ;;
2 ) date ;;
3 ) free -m ;;
4 ) df -h ;;
5 ) service postfix status
   service dovecot status
   service squid status
   service smb status
   service openvpn status
   service vsftpd status
   service httpd status
   service dhcpd status
   service named status ;;
6 ) ifconfig ;;
7 ) ping google.com ;;
8 ) uptime ;;
9 ) w ;;
10 ) top ;;
11 ) echo -n "enter the shutdown time in 24hr format(eg: 14:45)>"
    read time
    echo " Your linux machine will shutdown at $time"
    shutdown -h $time ;;
esac
done
#Now save the file and exit from the editor


Set execute permission
[root@server ~] chmod 755 basic_info


Run the Script and do tasks
[root@server ~] ./basic_info

Thanks for visiting, leave your comments and feedbacks.........

0 comments:

Related Posts Plugin for WordPress, Blogger...

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Bluehost Coupons