Wednesday, 20 April 2016

Area & Circumference of a circle - Shell script for Mac OS X

Guys in todays post let us look into a simple basic Mathematics problem. Let us automate the calculation of area and circumference of a circle, using a simple bash script. It's an easy script useful for learning some basic shell scripting.

Note : Value of pi used is a constant value rounded off to 3.142

#!/bin/bash
#program to calculate area and circumference of a circle

echo "=========================================="
echo "Area & Circumference of Circle Calculator"
echo "=========================================="

pi=3.142

echo "Please enter the radius of the circle : "
read radius

circumference=`expr "2*$pi*$radius"|bc`
echo "Circumference of circle : $circumference"
area=`expr "$pi*$radius*$radius"|bc`

echo "Area of circle : $area"

Output :

./AreaOfCircle.sh
==========================================
Area & Circumference of Circle Calculator
==========================================
Please enter the radius of the circle : 
5
Circumference of circle : 31.420

Area of circle : 78.550

Also do check out my previous post on Simple Interest Tool for additional scripting reference.

Script to check if a server / machine is up and running

Guys you might often come across some situations where you want to check if a server or machine is physically up and running. Quite obviously you would use the ping command to do so.

But in today's post let us write a simple bash script to automate this.

#!/bin/bash
#program to check if a server/machine is up and running

ipaddr=192.168.1.34

ping -c 4 $ipaddr >> /dev/null

if [[ $? -ne 0 ]]
then
echo "FAIL: Server seems to be down and not responding" 

else
echo "SUCCESS : Server is up and running"


fi

Note : $? is a special Unix variable to check if the previous command was executed successfully or not. It returns a numerical value - either 0 or 1. If the command was executed successfully, it returns 0, else if not, it returns 1.

In above script, simply replace the variable 'ipaddr' value to your server's ip address and check.

Also note that by redirecting the output of the ping command to /dev/null, we are suppressing and silencing the output i.e the ping o/p will not be shown on terminal. If you want to see the exact output of ping, remove the ">> /dev/null" part.

Output :

./PingServer.sh
SUCCESS : Server is up and running

Cheers!

Simple Interest Calculation : Shell Script for Mac OS X

Guys, today we'll look into a very basic simple shell script to calculate the Simple Interest. For this we need 3 essential details :

Principal Amount
Rate of Interest
Period i.e No. of years

Here's the bash script to calculate the Simple Interest.

#!/bin/bash
#program to calculate simple interest

echo "================================"
echo "Simple Interest Calculation Tool"
echo "================================"
echo "Enter principal amount : "
read principal
echo "Enter Rate of Interest : "
read roi;
echo "Enter No. of years : "
read years;

simple_interest=`expr "($principal*$years*$roi)/100"|bc`
echo "Simple Interest = $simple_interest"

Output :

./SimpleInterest.sh
================================
Simple Interest Calculation Tool
================================
Enter principal amount : 
5000
Enter Rate of Interest : 
9.5
Enter No. of years : 
5

Simple Interest = 2375

If you note, we have used the bc command to evaluate our expression i.e the Simple Interest formula. More on bc can be read here.

How to identify available shells on Mac OS X

Guys you may be aware that you can find your current shell in Mac OSX or any Unix machine by typing the following in Terminal.

echo $SHELL
/bin/bash

But to identify the available shells on Mac OS X type the following :

cat /etc/shells
# List of acceptable shells for chpass(1).
# Ftpd will not allow users to connect who are not using
# one of these shells.

/bin/bash
/bin/csh
/bin/ksh
/bin/sh
/bin/tcsh
/bin/zsh

Also, if you ant to change your default shell, type this :

chsh
Changing shell for ironcladzone.

Password for ironcladzone: 

Hope it helps. Cheers!

Saturday, 9 April 2016

GRE GMAT CAT Wordlist - TurboPack 8

Hi there! Hows it going today? Hope the previous TurboPacks are helping you in a small and efficient way in your preparations. Well let me know your valuable suggestions and comments to improve the quality and/or overall experience.


For now, let's continue with the latest TurboPack 8 for the day.

supple : flexible, bending and moving easily, limber
mogul : powerful person
lofty : very high
wholesome : healthful
indigence : extreme poverty
aspersion : slanderous remark, attack on someone's reputation
archetype : prototype, a typical example
gorge : narrow canyon, narrow valley, throat
putrid : foul smelling, decaying or rotten smell
simulate : imitate, pretend

Folks, more TurboPacks are on the way. Make sure to check for my previous TurboPacks 1-7 for reference. Again let me repeat that try to work on small batches of words at a time and focus on them thoroughly. Hope it helps. Ciao!

Thursday, 7 April 2016

GRE GMAT CAT Wordlist - TurboPack 7

Hi guys! hows it going? Hows your verbals preparation coming along. Hope the previous TurboPacks are useful in some way. Kindly do post your valuable comments and suggestions guys.



Here's another small batch of 10 Turbo words for the day.

encircle : surround
armada : fleet of warships
garish : overbright in color, gaudy, showy
exhume : dig out from ground
ferret : hunt out of hiding, assiduous search for something
arid : dry, barren
jetsam : things thrown from a ship usually to lighten it
oust : expel, drive out
paragon : model of perfection, a perfect example, of perfect quality
exquisite : very finely made, very beautiful and delicate

And incase you missed it, here are the links to previous TurboPacks

TurboPack 1
TurboPack 2
TurboPack 3
Turbopack 4
TurboPack 5
TurboPack 6

Wednesday, 6 April 2016

GRE GMAT CAT Wordlist - TurboPack 6

Ola fellas! como estas? How you guys doing? Hope the TurboPacks are aiding your preparations. Let me know your valuable comments and suggestions and if any more assistance needed.


So the TurboPack 6 is as follows :

rebuke : scold harshly, sharply criticise
mischance : ill luck, bad luck
ineffectual : weak, not effective
shirk : avoid/neglect work or responsibility
petty : trivial, unimportant
respite : relief, time for rest
parable : short story with a moral or lesson
shrewd : clever, astute
mirage : unreal reflection, optical illusion
astral : relating to the stars

The TurboPack 7 will be posted tomorrow. Stay tuned folks.
Related Posts Plugin for WordPress, Blogger...
eXTReMe Tracker