In this tutorial, we take a look at a shell script that takes the information about Linux server like logged users, uptime, load average, free memory, disk usage. The script helps to see all info about the server in a second.
The administrator can modify the script bit if it requires to find system information from multiple server.
Script run commands w, uname, uptime, free and df. From the uptime command script take load average.
Shell Script to get server information
Let us check shell script to find server information.
#!/bin/bash #clear console clear #just echo welcome messages echo "This is information provided by $0 . Program starts now." echo "Hello, $USER" echo #print today's date echo "Today's date is `date`, this is week `date +"%V"`." echo #list of currently loged user via w command. echo "These users are currently connected:" w | cut -d " " -f 1 - | grep -v USER | sort -u echo #info about system with command uname and keys -m and -s echo "This is `uname -s` running on a `uname -m` processor." echo #info about uptime, using uptime command echo "This is the uptime information:" uptime echo #info about free memory via free command echo "Free memory:" free echo #info about disk usage echo "Disk usage:" df -kh echo
Below is the script output.
This is information provided by ./system_info.sh . Program starts now. Hello, linoxide Today's date is Sunday, March 3 2013 22:31:43 +0200, this is week 09. These users are currently connected: linoxide This is Linux running on a i686 processor. This is the uptime information: 22:31:43 up 1:24, 2 users, load average: 0.45, 0.18, 0.07 Free memory: total used free shared buffers cached Mem: 3374792 1589476 1785316 0 96720 725652 -/+ buffers/cache: 767104 2607688 Swap: 4192924 0 4192924 Disk usage: Filesystem Size Used Avail Use% mounted /dev/sda1 42G 5,5G 35G 14% / tmpfs 1,7G 0 1,7G 0% /lib/init/rw udev 1,7G 168K 1,7G 1% /dev tmpfs 1,7G 160K 1,7G 1% /dev/shm /dev/sda6 184G 26G 149G 15% /home