Tags » Bash Script

Script for taking system information


#!/bin/bash
# unset any variable which system may be using

# clear the screen
clear

# Define Variable tecreset
tecreset=$(tput sgr0)

# Check if connected to Internet or not
ping -c 1 google.com &> /dev/null && echo -e '\E[32m'"Internet: $tecreset Connected" || echo -e '\E[32m'"Internet: $tecreset Disconnected"

# Check OS Type
os=$(uname -o)
echo -e '\E[32m'"Operating System Type :" $tecreset $os

# Check OS Release Version and Name
cat /etc/os-release | grep 'NAME\|VERSION' | grep -v 'VERSION_ID' | grep -v 'PRETTY_NAME' > /tmp/osrelease
echo -n -e '\E[32m'"OS Name :" $tecreset  && cat /tmp/osrelease | grep -v "VERSION" | cut -f2 -d\"
echo -n -e '\E[32m'"OS Version :" $tecreset && cat /tmp/osrelease | grep -v "NAME" | cut -f2 -d\"

# Check Architecture
architecture=$(uname -m)
echo -e '\E[32m'"Architecture :" $tecreset $architecture

# Check Kernel Release
kernelrelease=$(uname -r)
echo -e '\E[32m'"Kernel Release :" $tecreset $kernelrelease

# Check hostname
echo -e '\E[32m'"Hostname :" $tecreset $HOSTNAME

# Check Internal IP
internalip=$(hostname -I)
echo -e '\E[32m'"Internal IP :" $tecreset $internalip

# Check External IP
externalip=$(curl -s ipecho.net/plain;echo)
echo -e '\E[32m'"External IP : $tecreset "$externalip

# Check DNS
nameservers=$(cat /etc/resolv.conf | sed '1 d' | awk '{print $2}')
echo -e '\E[32m'"Name Servers :" $tecreset $nameservers 

# Check Logged In Users
who>/tmp/who
echo -e '\E[32m'"Logged In users :" $tecreset && cat /tmp/who 

# System entropy
entropy=$(cat /proc/sys/kernel/random/entropy_avail)
echo -e '\E[32m'"Entropy Value :" $tecreset $entropy

# Check RAM and SWAP Usages
free -h | grep -v + > /tmp/ramcache
echo -e '\E[32m'"Ram Usages :" $tecreset
cat /tmp/ramcache | grep -v "Swap"
echo -e '\E[32m'"Swap Usages :" $tecreset
cat /tmp/ramcache | grep -v "Mem"

# Check Disk Usages
df -Th| grep 'Filesystem\|/dev/sda*\|/dev/mapper/*' > /tmp/diskusage
echo -e '\E[32m'"Disk Usages :" $tecreset 
cat /tmp/diskusage

# Check Load Average
loadaverage=$(top -n 1 -b | grep "load average:" | awk '{print $10 $11 $12}')
echo -e '\E[32m'"Load Average :" $tecreset $loadaverage

# Check System Uptime
tecuptime=$(uptime | awk '{print $3,$4}' | cut -f1 -d,)
echo -e '\E[32m'"System Uptime Days/(HH:MM) :" $tecreset $tecuptime

# Establesd Internet Connection
netstat -natp | grep ESTABLISHED | awk '{print $5,$7}' > /tmp/estb
echo -e '\E[32m'"Established Connections :" $tecreset
cat /tmp/estb

# Enable Repolist
yum repoinfo | grep Repo-id | awk -F : '{print $2}' > /tmp/repolist
echo -e '\E[32m'"Enabled Repo :" $tecreset 
cat /tmp/repolist

# Unset Variables
unset tecreset os architecture kernelrelease internalip externalip nameserver loadaverage

# Remove Temporary Files
rm /tmp/osrelease /tmp/who /tmp/ramcache /tmp/diskusage /tmp/repolist /tmp/estb

Bash Script

Gentoo Linux, compilation of packages's time

I had heard some complaints that in Gentoo Linux it takes way too much time to compile the packages that one would install in a “normal system”. 275 more words

Insurance premium reminder: Another step to my automated reminder service

I already had set up a reminder process using which I get periodic notification to back up my data. This time I applied the same thought along with email reminder for my due insurance premiums. 275 more words

Bash Script

More: Array Subset, loop and xargs

Last week I had a requirement to fetch details of some records. For simplicity let’s assume records are id of some entity; I need to get details from an API for those id. 299 more words

Bash Script

writing script to Automate running Metasploit services, and call it from anywhere

Hi guys, that’s been a while I didn’t have time to update my blog. I would like to write a simple post about how to automate some works and run them easily any time. 345 more words

Hands On

Clear OS X Print Queues With Puppet

One of the issues with public Mac’s are users pausing the print queue’s and then logging out, or not deleting print jobs that may have failed for various reasons. 378 more words

Mac Admin

Start service on system startup using Upstart

I’m using Upstart Event System to start uTorrent server when system is up. The setup process is pretty simple and the most useful advantage is- if the job gets terminated then it would be restarted. 184 more words

Bash Script