Ravindra BagaleCourses & study guides मराठी Track your progress

Ravi Sir's Cyber Security Cards › Revision Cards

Basic Shell Scripting

Basic Shell Scripting A shell script is a text file of Linux commands that run one after another. Write NAME="Raja" with no spaces around =. Use it as "$NAME" , inside double quotes. A script that counts today’s failed SSH logins and shows the top 3 attacker IPs, using grep, awk, sort and uniq -c. N

Basic Shell Scripting A shell script is a text file of Linux commands that run one after another. Write NAME="Raja" with no spaces around =. Use it as "$NAME" , inside double quotes. A script that counts today’s failed SSH logins and shows the top 3 attacker IPs, using grep, awk, sort and uniq -c. N
Basic Shell Scripting · Download PNG
Read card text

What this card says

What it is

A shell script is a text file of Linux commands that run one after another.

Variables

Write NAME="Raja" with no spaces around =.

Use it as "$NAME", inside double quotes.

Example

A script that counts today’s failed SSH logins and shows the top 3 attacker IPs, using grep, awk, sort and uniq -c.

Common mistake

NAME = "Raja" with spaces. Bash thinks NAME is a command and gives an error.

ConceptSyntax
VariableNAME="Ruhi", use $NAME or ${NAME} (no spaces around =)
Command outputTODAY=$(date +%F)
Arguments$1, $2, all: $@, count: $#
Exit status of last command$? (0 = success)
Test file existsif [ -f /etc/nginx/nginx.conf ]; then ... fi

Learn more in the lesson: 6.11 Basic Shell Scripting

See all Ravi Sir's Cyber Security Cards