Bash Scripting - InaFricke/SYS-255 GitHub Wiki

Bash Scripting

bash -version version

which bash file path

Path Environment Variable

echo $PATH

The Path Environment Variable is very important. It tells your Bash interpreter, which directories to scan for applications that match your command.

Enviorment variables

https://www.techrepublic.com/article/linux-101-what-are-environment-variables/

CHange in paths

root has access to the root bin and ina has more specific paths than root

Unlike Windows, Linux hidden files are those files that have a leading period ("."). To see these files, enter ls -la

Up and down arrows to get back to previous statments

cd - Adding a dash symbol (-) to the cd command returns the shell to the previous working directory

history history of commands

Running a bash script

Vi info.sh

run bash info.sh

./info.sh run it directly

changing the permissions of a script file

`chmod XXX file.sh ; ls -la file.sh

Parsing script

Pipeling with |

Creating a script

Install tree

Sudo yum install tree

Loop script

vi loop.sh

The semicolons in the one-liner are replaced by newlines in the script

Pingsweeper.sh

switch to -c 1 (c2 was to long)

Output:

Source:

https://linuxsecurityblog.com/2019/08/21/write-a-ping-sweeper-in-4-lines-of-bash/

nslu.sh

# used to comment

Seq is a command so it needs the $(a b c ) a is the starting number, b is the increment and c is the ending number. I removed the echo in front of nslookup because it was not running the actual command and just writing out the 4 IPs.

psinput.sh

The screenshot above shows a pingsweeper script that pings twice -c 2and asks for the last bracket of the IP you want to ping. Forth is the variable I set the value of the answer to. I set forth into the ip variable.

Nmap

  1. sudo yum install nmap

  2. vi nmapinput.sh

  3. good list of Nmap parameter shttps://www.stationx.net/nmap-cheat-sheet/

  4. -F is the

I had some trouble getting a definitive answer for nmap command switch parameters. I believe a quick scan either uses - F or -sV. The screenshot below shows a quick nmap scan (-F) running on my 10.0.5.0/ 24 network.