Linux has many commands to view system information such as processor information, manufacturer name, serial number, and so on. You may need to execute multiple commands to collect this information. It’s also hard to remember all the commands and their options.

You can write a shell script to customize the information displayed based on your requirements.

We used to have to write many bash scripts for different purposes.

Now let’s write a new shell script that displays the system information we need every time we log into the shell.

The j script has six parts, with the following details:

  1. General system information
  2. CPU/ memory usage
  3. The disk usage exceeds 80%
  4. List the system WWN details
  5. Oracle DB instance
  6. Updatable packages

We have added the information we might need to each section based on our requirements. You can then modify the script as you wish.

This J script requires a number of tools, most of which we’ve already covered.

You can refer to the previous article for details of the tool.

  • Inxi – a great tool for checking hardware information on Linux
  • Dmidecode – An easy way to get Linux system hardware information
  • LSHW (Hardware Lister) – a nifty tool for getting hardware information on Linux
  • Hwinfo (Hardware information) – a nifty tool for detecting system hardware information on Linux
  • Python-hwinfo: Displays hardware information summaries using standard Linux utilities
  • How to use LSPCI, LSSCSI, LSUSB, and LSBLK to obtain device information about the Linux operating system
  • How do I check the system hardware manufacturer, model number, and serial number in Linux
  • How do I query the WWN, WWNN, and WWPN of an HBA in Linux
  • How to check the HP iLO firmware version from the Linux command line
  • How to check the wireless NETWORK card and WiFi information from the Linux command line
  • How do I check the CPU and hard disk temperatures on Linux
  • Referral on – A modular system and hardware monitoring tool for Linux
  • How do I check system configuration and hardware information on Linux

If you would like to add additional information to this script, please leave your request in the comments so we can help you.

The Bash script enables you to view Linux system information every time you log in to the Shell

This script prints system information to Terminal every time you log into the shell.

# vi /opt/scripts/system-info.sh
Copy the code
#! /bin/bash
echo -e "-------------------------------System Information----------------------------"
echo -e "Hostname:\t\t"`hostname`
echo -e "uptime:\t\t\t"`uptime | awk '{print $3,$4}' | sed 's/,//'`
echo -e "Manufacturer:\t\t"`cat /sys/class/dmi/id/chassis_vendor`
echo -e "Product Name:\t\t"`cat /sys/class/dmi/id/product_name`
echo -e "Version:\t\t"`cat /sys/class/dmi/id/product_version`
echo -e "Serial Number:\t\t"`cat /sys/class/dmi/id/product_serial`
echo -e "Machine Type:\t\t"`vserver=$(lscpu | grep Hypervisor | wc -l); if [ $vserver -gt0];then echo "VM"; else echo "Physical"; fi`
echo -e "Operating System:\t"`hostnamectl | grep "Operating System" | cut -d ' ' -f5 - `echo -e "Kernel:\t\t\t"`uname -r`
echo -e "Architecture:\t\t"`arch`
echo -e "Processor Name:\t\t"`awk -F':' '/^model name/ {print $2}' /proc/cpuinfo | uniq | sed -e 's/^[ \t]*//'`
echo -e "Active User:\t\t"`w | cut -d ' ' -f1 | grep -v USER | xargs -n1`
echo -e "System Main IP:\t\t"`hostname -I`
echo ""
echo -e "-------------------------------CPU/Memory Usage------------------------------"
echo -e "Memory Usage:\t"`free | awk '/Mem/{printf("%.2f%"), $3/$2*100}'`
echo -e "Swap Usage:\t"`free | awk '/Swap/{printf("%.2f%"), $3/$2*100}'`
echo -e "CPU Usage:\t"`cat /proc/stat | awk '/cpu/{printf("%.2f%\n"), ($2+$4)*100/($2+$4+$5)}' |  awk '{print $0}' | head -1`
echo ""
echo -e "-------------------------------Disk Usage >80%-------------------------------"
df -Ph | sed s/%//g | awk '{ if($5 > 80) print $0; } '
echo ""

echo -e "-------------------------------For WWN Details-------------------------------"
vserver=$(lscpu | grep Hypervisor | wc -l)
if [ $vserver -gt0]then
echo "$(hostname) is a VM"
elsecat /sys/class/fc_host/host? /port_namefi
echo ""

echo -e "-------------------------------Oracle DB Instances---------------------------"
if id oracle >/dev/null 2>&1; then
/bin/ps -ef|grep pmon
then
else
echo "oracle user does not exist on $(hostname)"
fi
echo ""

if (( $(cat /etc/*-release | grep -w "Oracle|Red Hat|CentOS|Fedora" | wc -l) > 0))then
echo -e "-------------------------------Package Updates-------------------------------"
yum updateinfo summary | grep 'Security|Bugfix|Enhancement'
echo -e "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --"
else
echo -e "-------------------------------Package Updates-------------------------------"
cat /var/lib/update-notifier/updates-available
echo -e "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --"
fi
Copy the code

Save the above script contents to a file system-info.sh, then add the executable permission:

# chmod +x ~root/system-info.sh
Copy the code

When the script is ready, add the path of the script file to the end of the.bash_profile file (Red Hat systems: CentOS, Oracle Linux, Fedora) :

# echo "/root/system-info.sh" >> ~root/.bash_profile
Copy the code

Execute the following command for the changes to take effect:

# source ~root/.bash_profile
Copy the code

For Debian systems, you may need to add the file path to the.profile file:

# echo "/root/system-info.sh" >> ~root/.profile
Copy the code

Run the following command for the changes to take effect:

# source ~root/.profile
Copy the code

You may have seen output similar to this before when you ran the source command above. Starting next time, you’ll see this information every time you log into the shell. Of course, you can always execute this script manually if necessary.

-------------------------------System Information--------------------------- Hostname: daygeek-Y700 uptime: 1:20 1 Manufacturer: LENOVO Product Name: 80NV Version: Lenovo ideapad Y700-15ISK Serial Number: AA0CMRN1 Machine Type: Physical Operating System: Manjaro Kernel: 4.19.80-1-Manjaro Architecture: x86_64 Processor Name: Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz Active User: DayGeek Renu Thanu System Main IP: 192.168.1.6 192.168.122.1 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- CPU/Memory Usage -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- the Memory Usage: 37.28% Swap Usage: 0.00% CPU Usage: 15.43% -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - Disk Usage > 80% -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Filesystem Size, informs the Avail the Use Mounted on/dev/nvme0n1p1 217 G to 202 G 4.6 G / 98 / dev/loop0 109 m 109 m 0 100 / var/lib/snapd/snap/odrive - unofficial / 2 /dev/loop1 91M 91M 0 100 /var/lib/snapd/snap/core/6405 /dev/loop2 90M 90M 0 100 /var/lib/snapd/snap/core/7713 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - For WWNS Details -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - CentOS8.2daygeek.com is a VM -------------------------------Oracle DB Instances--------------------------- oracle user does not exist on CentOS8.2daygeek.com -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Package Updates -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - 13 Security notice (s)  9 Important Security notice(s) 3 Moderate Security notice(s) 1 Low Security notice(s) 35 Bugfix notice(s) 1 Enhancement  notice(s) -----------------------------------------------------------------------------Copy the code

Via: www.2daygeek.com/bash-shell-…

Magesh Maruthamuthu (lujun9972

This article is originally compiled by LCTT and released in Linux China