Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 24ea39b

Browse files
committed
first commit
0 parents  commit 24ea39b

26 files changed

+527
-0
lines changed

Addition.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
echo .Enter the First Number: .
3+
read a
4+
echo .Enter the Second Number: .
5+
read b
6+
x=$(expr "$a" + "$b")
7+
echo $a + $b = $x
8+

Armstrong.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
echo "Enter A Number"
3+
read n
4+
arm=0
5+
temp=$n
6+
while [ $n -ne 0 ]
7+
do
8+
r=$(expr $n % 10)
9+
arm=$(expr $arm + $r \* $r \* $r)
10+
n=$(expr $n / 10)
11+
done
12+
echo $arm
13+
if [ $arm -eq $temp ]
14+
then
15+
echo "Armstrong"
16+
else
17+
echo "Not Armstrong"
18+
fi
19+
20+

Binary2Decimal.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
echo "Enter a number :"
3+
read Binary
4+
if [ $Binary -eq 0 ]
5+
then
6+
echo "Enter a valid number "
7+
else
8+
while [ $Binary -ne 0 ]
9+
do
10+
Bnumber=$Binary
11+
Decimal=0
12+
power=1
13+
while [ $Binary -ne 0 ]
14+
do
15+
rem=$(expr $Binary % 10 )
16+
Decimal=$((Decimal+(rem*power)))
17+
power=$((power*2))
18+
Binary=$(expr $Binary / 10)
19+
done
20+
echo " $Decimal"
21+
done
22+
fi

Check-Disk-Space.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
MAX=95
2+
3+
PART=sda1
4+
5+
USE=`df -h |grep $PART | awk '{ print $5 }' | cut -d'%' -f1`
6+
if [ $USE -gt $MAX ]; then
7+
echo "Percent used: $USE" | mail -s "Running out of disk space" $EMAIL
8+
fi

Colorfull.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
3+
clear
4+
echo -e "\033[1m Hello World"
5+
# bold effect
6+
echo -e "\033[5m Blink"
7+
# blink effect
8+
echo -e "\033[0m Hello World"
9+
# back to noraml
10+
11+
echo -e "\033[31m Hello World"
12+
# Red color
13+
echo -e "\033[32m Hello World"
14+
# Green color
15+
echo -e "\033[33m Hello World"
16+
# See remaing on screen
17+
echo -e "\033[34m Hello World"
18+
echo -e "\033[35m Hello World"
19+
echo -e "\033[36m Hello World"
20+
21+
echo -e -n "\033[0m"
22+
# back to noraml
23+
echo -e "\033[41m Hello World"
24+
echo -e "\033[42m Hello World"
25+
echo -e "\033[43m Hello World"
26+
echo -e "\033[44m Hello World"
27+
echo -e "\033[45m Hello World"
28+
echo -e "\033[46m Hello World"
29+
30+
31+
echo -e "\033[0m Hello World"
32+

Decimal2Binary.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
3+
for ((i=32;i>=0;i--)); do
4+
r=$(( 2**$i))
5+
Probablity+=( $r )
6+
done
7+
8+
[[ $# -eq 0 ]] && { echo -e "Usage \n \t $0 numbers"; exit 1; }
9+
10+
echo -en "Decimal\t\tBinary\n"
11+
for input_int in $@; do
12+
s=0
13+
test ${#input_int} -gt 11 && { echo "Support Upto 10 Digit number :: skiping \"$input_int\""; continue; }
14+
15+
printf "%-10s\t" "$input_int"
16+
17+
for n in ${Probablity[@]}; do
18+
19+
if [[ $input_int -lt ${n} ]]; then
20+
[[ $s = 1 ]] && printf "%d" 0
21+
else
22+
printf "%d" 1 ; s=1
23+
input_int=$(( $input_int - ${n} ))
24+
fi
25+
done
26+
echo -e
27+
done

Division.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
echo .Enter the First Number: .
3+
read a
4+
echo .Enter the Second Number: .
5+
read b
6+
echo "$a / $b = $(expr $a / $b)"
7+
8+

Encrypt.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
echo "Welcome, I am ready to encrypt a file/folder for you"
3+
echo "currently I have a limitation, Place me to teh same folder, where a file to be encrypted is present"
4+
echo "Enter the Exact File Name with extension"
5+
read file;
6+
gpg -c $file
7+
echo "I have encrypted the file sucessfully..."
8+
echo "Now I will be removing the original file"
9+
rm -rf $file

EvenOdd.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
echo "Enter The Number"
3+
read n
4+
num=$(expr $n % 2)
5+
if [ $num -eq 0 ]
6+
then
7+
echo "is a Even Number"
8+
else
9+
echo "is a Odd Number"
10+
fi
11+
12+

Factorial.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
echo "Enter The Number"
3+
read a
4+
fact=1
5+
while [ $a -ne 0 ]
6+
do
7+
fact=$(expr $fact \* $a)
8+
a=$(expr $a - 1)
9+
done
10+
echo $fact
11+
12+

Fibonacci.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
echo "How many numbers do you want of Fibonacci series ?"
3+
read total
4+
x=0
5+
y=1
6+
i=2
7+
echo "Fibonacci Series up to $total terms :: "
8+
echo "$x"
9+
echo "$y"
10+
while [ $i -lt $total ]
11+
do
12+
i=`expr $i + 1 `
13+
z=`expr $x + $y `
14+
echo "$z"
15+
x=$y
16+
y=$z
17+
done

Hello.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
# My first script
3+
4+
echo "Hello World!"

Interactive.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#! /bin/bash
2+
echo "Hey what's Your First Name?";
3+
read a;
4+
echo "welcome Mr./Mrs. $a, would you like to tell us, Your Last Name";
5+
read b;
6+
echo "Thanks Mr./Mrs. $a $b for telling us your name";
7+
echo "*******************"
8+
echo "Mr./Mrs. $b, it's time to say you good bye"

Multiplication.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
echo .Enter the First Number: .
3+
read a
4+
echo .Enter the Second Number: .
5+
read b
6+
echo "$a * $b = $(expr $a \* $b)"

Prime.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
echo “Enter Any Number”
3+
read n
4+
i=1
5+
c=1
6+
while [ $i -le $n ]
7+
do
8+
i=$(expr $i + 1)
9+
r=$(expr $n % $i)
10+
if [ $r -eq 0 ]
11+
then
12+
c=$(expr $c + 1)
13+
fi
14+
done
15+
if [ $c -eq 2 ]
16+
then
17+
echo “Prime”
18+
else
19+
echo “Not Prime”
20+
fi

Process.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#! /bin/bash
2+
echo "Hello $USER"
3+
echo "Hey i am" $USER "and will be telling you about the current processes"
4+
echo "Running processes List"
5+
ps

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
A collection of Bash scripts from [TecMint.com's tutorial](http://www.tecmint.com/learning-shell-scripting-language-a-guide-from-newbies-to-system-administrator/).
2+
3+
1. Hello.sh: get a simple output
4+
1. Process.sh: execute more than one command in a script
5+
1. Interactive.sh: a simple but very much interactive script
6+
1. Special_patter.sh: draw a diamond pattern with dots(.)
7+
1. Colourfull.sh: provide you with the output of several colours
8+
1. Encrypt.sh: encrypt a file/folder with password
9+
1. Server-Health.sh: report server related information
10+
1. Disk_space.sh: check if the disk space crosses the limit
11+
1. up.sh: move up a directory in shell script
12+
1. Randomfile.sh: create unique file/folder automatically with date and time stamp
13+
1. Collectnetworkinfo.sh: gather information related to server
14+
1. Convertlowercase.sh: convert data either from the file or standard input to lowercase
15+
1. Simplecacl.sh: a simple calculator
16+
1. Addition.sh: perform addition of two numbers
17+
1. Substraction.sh: perform substraction of two numbers
18+
1. Multiplication.sh: perform multiplication of two numbers
19+
1. Division.sh: perform division of two numbers
20+
1. Table.sh: print table of any number
21+
1. EvenOdd.sh: checks if a number input from standard input is odd or even
22+
1. Factorial.sh: generate the factorial of a number
23+
1. Armstrong.sh: check if a provided number is Armstrong or not
24+
1. Prime.sh: check if a number is prime or not
25+
1. Fibonacci.sh: test if a number being entered is a Fibonacci or not
26+
1. Decimal2Binary.sh: convert Decimal Number to Binary
27+
1. Binry2Decimal.sh: convert Binary Number back to decimal

Server-Health.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
date;
3+
echo "uptime:"
4+
uptime
5+
echo "Currently connected:"
6+
w
7+
echo "--------------------"
8+
echo "Last logins:"
9+
last -a |head -3
10+
echo "--------------------"
11+
echo "Disk and memory usage:"
12+
df -h | xargs | awk '{print "Free/total disk: " $11 " / " $9}'
13+
free -m | xargs | awk '{print "Free/total memory: " $17 " / " $8 " MB"}'
14+
echo "--------------------"
15+
start_log=`head -1 /var/log/messages |cut -c 1-12`
16+
oom=`grep -ci kill /var/log/messages`
17+
echo -n "OOM errors since $start_log :" $oom
18+
echo ""
19+
echo "--------------------"
20+
echo "Utilization and most expensive processes:"
21+
top -b |head -3
22+
echo
23+
top -b |head -10 |tail -4
24+
echo "--------------------"
25+
echo "Open TCP ports:"
26+
nmap -p- -T4 127.0.0.1
27+
echo "--------------------"
28+
echo "Current connections:"
29+
ss -s
30+
echo "--------------------"
31+
echo "processes:"
32+
ps auxf --width=200
33+
echo "--------------------"
34+
echo "vmstat:"
35+
vmstat 1 5
36+
37+

Special_Pattern.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/bin/bash
2+
3+
MAX_NO=0
4+
5+
echo -n "Enter Number between (5 to 9) : "
6+
read MAX_NO
7+
8+
if ! [ $MAX_NO -ge 5 -a $MAX_NO -le 9 ] ; then
9+
echo "WTF... I ask to enter number between 5 and 9, Try Again"
10+
exit 1
11+
fi
12+
13+
clear
14+
15+
for (( i=1; i<=MAX_NO; i++ ))
16+
do
17+
for (( s=MAX_NO; s>=i; s-- ))
18+
do
19+
echo -n " "
20+
done
21+
for (( j=1; j<=i; j++ ))
22+
do
23+
echo -n " ."
24+
done
25+
echo ""
26+
done
27+
###### Second stage ######################
28+
for (( i=MAX_NO; i>=1; i-- ))
29+
do
30+
for (( s=i; s<=MAX_NO; s++ ))
31+
do
32+
echo -n " "
33+
done
34+
for (( j=1; j<=i; j++ ))
35+
do
36+
echo -n " ."
37+
done
38+
echo ""
39+
done
40+
41+
42+
echo -e "\n\n\t\t\t Whenever you need help, Tecmint.com is always there"
43+

Substraction.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
echo .Enter the First Number: .
3+
read a
4+
echo .Enter the Second Number: .
5+
read b
6+
x=$(($a - $b))
7+
echo $a - $b = $x
8+
9+

Table.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
echo .Enter The Number upto which you want to Print Table: .
3+
read n
4+
i=1
5+
while [ $i -ne 10 ]
6+
do
7+
i=$(expr $i + 1)
8+
table=$(expr $i \* $n)
9+
echo $table
10+
done
11+
12+

0 commit comments

Comments
 (0)