Tags » Bash Script

Life is easier with bash scripts - Part 2

previous post of this series: Life is easier with bash scripts – Part 1


In a folder named ‘./Data/’ I had a number of folders each containing a zip file. 491 more words

Bash Script

Life is easier with bash scripts - Part 1

Though I had Ubuntu installed at my workstation for about a year, it was tough for me to switch from the comfort of windows to more involved Linux based systems.

611 more words
Bash Script

Script for taking system information

# unset any variable which system may be using

# clear the screen

# 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
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