Domestic Terrorism

The shooting at a Walmart in El Paso, Texas was a disturbing reminder of the rise in hate in this country. In fact, according to the FBI the number of hate crimes increased three years in a row…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Basic Shell Scripting.

Usually shells are interactive that mean, they accept command as input from users and execute them. However some time we want to execute a bunch of commands routinely, so we have type in all commands each time in terminal.
As shell can also take commands as input from file we can write these commands in a file and can execute them in shell to avoid this repetitive work. These files are called
Shell Scripts

#!/bin/bash ( called shebang, what interpreter we are going to use, here bash interpreter |e.g: chs, zsh, ksh )

#!/bin/python (here we are using python interpreter )

#!/bin/sh (shell interpreter)

Bash is consider to be a terminal , which gives you a much more streamlined experience when it comes to use Linux or Unix operating system

Shell is simply the shell that interpreter of commands

Example shell script : —

#!/bin/bash

Echo “ Hello World”

Output — Hello World

A storage location with specific location, can not start variable with number.

(no space before or after = sign | variable name should always be in upper case)

To use a variable value we wil use $

#!bin/bash

NAME=” Baljeet ”

Echo “My name is $NAME”

OUTPUT — My name is Baljeet

NAME=”Baljeet”

SPORT=”Foot”

Echo “ the most popular sport is ${SPORT}ball ”

OUTPUT — the most popular sport is football

-p (prompt)

#!/bin/bash

Read -p “ Enter your name: ” NAME (variable name where we want to store it)

Echo “your name is $NAME”

OUTPUT — Enter your name

Baljeet

Your name is baljeet

(Wanted user to input full name)

#!/bin/bash

echo “ Enter your full name: ”

Read FNAME LNAME

Echo “your name is $FNAME $LNAME”

OUTPUT — enter your full name

Baljeet singh

Your name is Baljeet singh

OR

echo “ Enter your name and your age: ”

Read FNAME AGE

Echo “your name is $FNAME and your age is $AGE”

OUTPUT — enter your full name and your age:

Baljeet 20

Your name is Baljeet singh and your age is 20

They can be used for tests

— — IF — —

#!/bin/bash

If [condition]:

then

condition

fi (closing of if statement)

OR

#!/bin/bash

NAME=” Baljeet ”

If [“$NAME” = “ Baljeet”]:

then

Echo “welcom Baljeet”

fi

OUTPUT — welcome Baljeet

— — if else — — — — —

#!/bin/bash

If [condition]:

then

condition

else

condition

fi

EX: —

#!/bin/bash

Echo “ please enter your username ”

Read NAME

If [“$NAME” = “Eliot”]:

then

echo “welcom back elliot”

else

Echo “invalid username”

fi

Tests are used for automating processings and task that required conditional data.

( Type — — help test )

IF WORDLIST DIRECTORY EXIST

#!/bin/bash

If [ -d /usr/share/wordlists]:

then

echo “ yes it exists”

else

echo “file dosent exists”

fi

IF WANT TO FIND ROCKYOU.TXT IN WORDLISTS

#!/bin/bash

If [ -d /usr/share/wordlists/rockyou.txt]:

then

echo “ yes it exists”

else

echo “file dosent exists”

fi

IF WANT TO CHEK SHADOW FILE WHICH CONTAIN HASH PASWORDS

#!/bin/bash

If [-e /etc/shadow]:

then

echo “Yes it exists”

else

echo “the file dosent exists”

fi

#!/bin/bash

for VARIABLE in $(): do

commands

done

EX —

PRINT OUT LIST OF NAMES

(Create a txt file with names)

#!/bin/bash

for NAMES in $(cat names.txt): do OR cat or type

Echo “The names are: $NAMES”

done

#!/bin/bash

#simplePingSweepScript

echo “enter your subnet :”

read $SUBNET

for IP in $(seq 1 254): do

Ping -c 1 $SUBNET.$IP

done

A piece of code that perform specific tasks, use it to help reduce repetition. Use function to sort out code or maintain the code .

*1st way

CREATE DIRECTORIES IF EXIST, E.G IF SHADOW OR PASSWORD FILE EXIST

#!/bin/bash

function functionname()

{

#code

}

*2nd way

function1()

{

#code

}

EX —

#!/bin/bash

{

If [ -e /etc/shadow ];

then

echo “yes, it exists: ”

else

echo “file dosent exist: “

fi

}

{

If [ -e /etc/passwd ];

then

echo “yes, it exists: ”

else

echo “file dosent exist: “

fi

}

— — — -OR — — — -

Recursion , function in function

#!/bin/bash

{

If [ -e /etc/shadow ];

then

echo “yes, it exists: ”

else

echo “file dosent exist: “

fi

}

{

If [ -e /etc/passwd ];

then

echo “yes, it exists: ”

else

echo “file dosent exist: “

fi

}

are variables that contain values or data that passed through terminal when we execute the script. Used in regards to position with executing the script

Script Allow you to create a user | automate the process of adding a user

$0 — $9

(positional parameters from 0 to 9 | when executing the script para. Will be given to script one by one)

#!/bin/bash

echo “Execution of script : $0”

echo “enter the name of user:$1” (data is going to store in these positional parameters)

#adding user

adduser — home /$1 $1

Run — ./aduser.sh user1

OUTPUT —

Will use gpg tool gnup privacy guard | allows you to encrypt data and generate keys

#!/bin/bash

echo “This is a simple file encryptor/decrypter”

echo “ choose what to do”

Choice=”Encrypt Decrypt”

Select option in $choice; do

If [ $REPLY = 1 ];

then

echo “you have selected encryption”

echo “enter the file name”

Read file;

gpg -c $file

echo “the file has been encrypted”

else

echo “you have selected decryption”

echo “enter the file name”

Read file2;

gpg -d $file2

Echo “the file has been decrypted”

fi

done

OUTPUT — — list files and open the new generated file.

Add a comment

Related posts:

Repentance

I started sifting my days like how I would pick a flower apart good, bad, okay, sad, happy, hurting, pain, peace but when my hands are finally empty, I’m left staring down at the fallen petals the…

How to Choose the Right Social Media for YOU

It seems like everyone is always shouting the praises of this or that social media platform. Facebook is the best! Wait, nevermind, Facebook took away organic reach. Okay, then Instagram is the best…