UNIT - II
Dynamic Configuring networking and
hostname resolution
• Step 1: Log in to the AWS Management Console
• Step 2: Navigate to the EC2 Dashboard
• Step 3: Launch an EC2 Instance
• Step 4: Connect to Your EC2 Instance
• Step 6: Configure Networking Inside the Instance
Step 6: Configure Networking Inside the
Instance
For Linux Instances:
Open the terminal and edit the network configuration file:
• Configure the network settings, including IP address, subnet mask, gateway, and DNS servers
• Save the file and exit.
• Restart the networking service:
Step 6: Configure Networking Inside the
Instance
For Windows Instances:
• Open the Network and Sharing Center from the Control Panel.
• Click on "Change adapter settings."
• Right-click on your network adapter, select "Properties."
• Select "Internet Protocol Version 4 (TCP/IPv4)" and click "Properties."
• Choose "Obtain an IP address automatically" for DHCP or enter the
static IP, subnet mask, gateway, and DNS servers for a static
configuration.
• Click "OK" to save the changes.
Step 7: Configure Hostname Resolution
• Open the hosts file for editing:
• For Linux
• For Windows:
• Add an entry for your instance's private IP and desired hostname:
• Save the file and exit.
Step 8: Verify Configuration
• Open a terminal or command prompt and ping the hostname to
verify that the hostname resolution is working correctly.
Network Services Configuration
For Linux Instances
• Configure Services to Start Automatically
• Use the systemctl command to enable services at boot.
• For example, to enable the SSH service
• Start, Stop, and Check Status:
• Start a service:
• Stop a service:
• Check the status:
Network Services Configuration
For Windows Instances
• Configure Services to Start Automatically:
• Open the "Services" application. You can do this by pressing Win + R, typing
[Link], and pressing Enter.
• Locate the service you want to configure, right-click, and select "Properties."
• Set the "Startup type" to "Automatic" and click "OK.“
Start, Stop, and Check Status:
• Start a service:
• Right-click on the service, select "Start.“
• Stop a service:
• Right-click on the service, select "Stop.“
• Check the status:
• Right-click on the service, select "Properties," and check the "Service status."
Verify Configuration
• Reboot the instance to ensure that the services start automatically at
boot.
• After the reboot, check the status of the services to ensure they are
running.
Configure HTTP server log files
• Connect to Your EC2 Instance
• Navigate to Apache Configuration Directory
• Edit the Apache Configuration File
• Open the Apache configuration file using a text editor (e.g., sudo nano /etc/httpd/conf/[Link]).
• Enable Logging:
• Find the relevant <Virtual Host> block for your website and ensure that the Custom Log directive is
uncommented. You can customize the log format and file path
• Save and Restart Apache:
BASH SCRIPTING
DEFINITION
Bash (Bourne Again SHell) is a command processor that
typically runs in a text window where the user types
commands that cause actions.
PURPOSE
Bash scripting is a great way to automate different types of tasks in a system. Developers can
avoid doing repetitive tasks using bash scripting.
Bash scripting supports variables, conditional statements, and loops just like programming
languages.
KEY FEATURES OF BASH SHELL SCRIPTING
• Interactivity: Bash allows users to interact with the system in a command-line
environment.
• Scripting: Users can write scripts to automate tasks by combining multiple commands.
• Variables: Store and manipulate data using variables.
• Control Structures: Implement conditional statements and loops.
• Functions: Encapsulate code for reusability.
BASH SHELL
Advantages Disadvantages
It is simple. Any mistake while writing can be costly.
It helps to avoid doing repetitive tasks A new process launched for almost every shell
command executed
Easy to use
Slow execution speed
Frequently performed tasks can be automated
Compatibility problems between different
A sequence of commands can be run as a single
platforms
command.
HOW TO WRITE BASH SCRIPTS?
HOW TO WRITE BASH SCRIPTS?
Create a file with the .sh extension.
Write down the bash scripts within it
Provide execution permission to it
Execute the file
GENERAL PURPOSE COMMANDS
S. No Command Description Example
1 ls List files and directories in the current directory. ls
2 cd Change the current working directory. cd /path/to/directory
3 pwd Print the current working directory. pwd
4 cp Copy files or directories. cp [Link] /path/to/destination
5 mv Move or rename files or directories. mv [Link] [Link]
6 rm Remove/delete files or directories. rm [Link]
GENERAL PURPOSE COMMANDS
S. No Command Description Example
7 mkdir Create a new directory mkdir new_directory
8 rmdir Remove an empty directory. rmdir empty_directory
9 touch Create an empty file or update the timestamp of touch new_file.txt
an existing file
10 cat Display the contents of a file. cat [Link]
11 echo Display a message or the value of a variable. echo "Hello, World!"
12 Grep Search for a pattern in a file. grep "pattern" [Link]
GENERAL PURPOSE COMMANDS
S. No Command Description Example
13 find Search for files and directories based on various find /path/to/search -name "*.txt”
criteria
14 chmod Change the permissions of a file or directory. chmod +x [Link]
15 chown Change the owner of a file or directory chown user:group [Link]
16 ps Display information about running processes. ps aux
17 kill Terminate a process kill PID
18 df Display information about disk space usage. df -h
GENERAL PURPOSE COMMANDS
S. No Command Description Example
19 du Display the disk usage of files and directories. du -h
20 man Display the manual (documentation) for a command. man ls
21 who Displays all the users who have logged into the system who
currently.
22 cal display calendar cal
23 clear clean up the terminal clear
24 history get list of previous commands may be obtained history
WHICH COMMAND IS USED TO DISPLAY THE CURRENT DIRECTORY IN
LINUX?
WHICH COMMAND IS USED TO DISPLAY THE CURRENT DIRECTORY IN LINUX?
a) ls
b) cd
c) pwd
d) dir
WHAT COMMAND IS USED TO LIST THE CONTENTS OF A DIRECTORY
IN LINUX?
a) ls
b) dir
c) list
d) show
TO CREATE A NEW DIRECTORY IN LINUX, YOU WOULD USE THE
COMMAND:
a) mkdir
b) newdir
c) create
d) touch
WHAT COMMAND IS USED TO COPY FILES OR DIRECTORIES IN
LINUX?
a) mv
b) copy
c) cp
d) xcopy
TO REMOVE A FILE IN LINUX, YOU WOULD USE THE COMMAND:
a) delete
b) rm
c) del
d) erase
WHICH COMMAND IS USED TO CHANGE THE CURRENT USER'S
PASSWORD IN LINUX?
a) passwd
b) change
c) setpasswd
d) userpassword
THE COMMAND TO DISPLAY THE LAST FEW LINES OF A TEXT FILE IN
LINUX IS:
a) head
b) tail
c) cat
d) more
TO NAVIGATE TO THE HOME DIRECTORY OF THE CURRENT USER IN
LINUX, YOU WOULD USE THE COMMAND:
a) cd /
b) cd ~
c) cd home
d) cd ..
WHICH COMMAND IS USED TO FIND FILES IN LINUX BASED ON THEIR
NAMES?
a) locate
b) search
c) find
d) grep
THE COMMAND TO VIEW THE MANUAL (HELP) FOR A SPECIFIC
COMMAND IN LINUX IS:
a) man
b) help
c) info
d) view
ANSWERS:
1.C 2.A 3.A 4.C 5.B
6.A 7.B 8.B 9.C 10.A
REDIRECTION OPERATORS
S. No Command Description Example
1 > (Output Redirection) Redirects standard output to a file, overwriting the command > [Link]
file if it already exists.
2 >> (Append Output) Redirects standard output to a file, appending the command >> [Link]
output to the end of the file if it already exists.
3 < (Input Redirection) Redirects standard input from a file instead of the command < [Link]
keyboard
4 | (Pipe) Connects the output of one command to the input of command1 | command2
another, allowing the output of the first command to
serve as input for the second.
5 2> (Standard Error Redirects standard error output to a file command 2> [Link]
Redirection)
REDIRECTION OPERATORS
S. No Command Description Example
6 2>> (Append Standard Redirects standard error output to a file, command 2>> [Link]
Error) appending to the end of the file.
7 &> or >& (Redirect Redirects both standard output and standard command &>
Standard Output and error to a file. output_and_error.txt
Standard Error)
8 <() (Process Substitution) Allows the output of a command to be used as a diff <(command1)
file in another command. <(command2)
9 >() (Process Substitution Allows the output of a command to be used as a command > >(tee
for Writing) file to write to. [Link])
10 << (Here Document) Allows input to be taken from the lines following cat << EOF
the operator until a specified delimiter is This is a multi-line input.
encountered. It ends at the delimiter
EOF.
EOF
WHICH REDIRECTION OPERATOR IS USED TO REDIRECT STANDARD
OUTPUT TO A FILE IN LINUX?
a) >
b) <
c) >>
d) |
WHAT DOES THE 2> REDIRECTION OPERATOR DO IN LINUX?
a) Redirects standard output to a file.
b) Redirects standard error to a file.
c) Appends standard output to a file.
d) Creates a new file.
TO APPEND THE OUTPUT OF A COMMAND TO AN EXISTING FILE IN
LINUX, YOU WOULD USE THE REDIRECTION OPERATOR:
a) >
b) >>
c) <
d) |
THE COMMAND COMMAND1 | COMMAND2 IN LINUX USES WHICH
TYPE OF REDIRECTION?
a) Input Redirection
b) Output Redirection
c) Pipe Redirection
d) Error Redirection
WHAT DOES THE &> REDIRECTION OPERATOR DO IN LINUX?
a) Redirects standard output and standard error to a file.
b) Redirects standard input from a file.
c) Redirects standard output to a file.
d) Redirects standard error to the screen.
ANSWERS
1.C 2.B 3.B 4.C 5.A
STDIN (STANDARD INPUT)
It stands for standard input, and is used for taking text as an input.
Linux assigns unique values 0 = stdin
By default, STDIN is connected to the keyboard, and commands read input from
the keyboard unless redirected.
STDOUT (STANDARD OUTPUT)
STDOUT is the standard output stream.
By default, STDOUT is connected to the terminal, and commands display their output
on the terminal.
File Descriptor: 1
STDERR (STANDARD ERROR)
STDERR is the standard error stream
It is used to output error messages and diagnostic information separate from the regular
output.
Like STDOUT, STDERR is connected to the terminal by default.
WHICH FILE DESCRIPTOR IS ASSOCIATED WITH STANDARD INPUT IN
LINUX?
a) STDIN
b) STDOUT
c) STDERR
d) STDFILE
WHAT IS THE DEFAULT FILE DESCRIPTOR FOR STANDARD OUTPUT IN
LINUX?
a) STDIN
b) STDOUT
c) STDERR
d) STDFILE
IN A LINUX COMMAND, WHICH SYMBOL IS USED TO REPRESENT
STANDARD OUTPUT?
a) >
b) <
c) &
d) |
WHICH FILE DESCRIPTOR IS USED FOR ERROR MESSAGES IN LINUX?
a) STDIN
b) STDOUT
c) STDERR
d) STDFILE
WHAT DOES THE SYMBOL 2> SIGNIFY IN A LINUX COMMAND?
a) Redirects Standard Output to a file.
b) Redirects Standard Input from a file.
c) Redirects Standard Error to a file.
d) Redirects both Standard Output and Standard Error to a file.
ANSWERS:
1.A 2.B 3.A 4.C 5.C
ECHO COMMAND
The echo command in Linux is a built-in command that allows users to display lines of text
or strings that are passed as arguments.
OPTION: This is optional and can modify the behavior of the echo command.
STRING: The text or message that you want to display.
EXAMPLES
1. Print a Simple Message
2. Print a variable
3. Display without newline
4. Escape Characters
BASH VARIABLES
Data is stored at a particular memory address and then
Variables let you store, read, access, and manipulate data. It can be accessed as well as
modified when required
Syntax -
Example -
Accessing Variable Value
Concatenating Variables:
String Variables
Numeric Variables
Boolean Variables
SPECIAL VARIABLES
Positional Parameters - $0, $1, $2, ...: Represent the script or command
name, and the command-line arguments.
Environment Variables: $HOME, $USER, $PATH, etc.: Represent system or
user-specific information
Performing Arithmetic
Local and Global Scope
IN PROGRAMMING, WHAT IS THE PROCESS OF COMBINING TWO OR
MORE STRINGS INTO A SINGLE STRING CALLED?
a) Concatenating
b) Merging
c) Joining
d) Appending
WHICH OPERATOR IS COMMONLY USED FOR CONCATENATING
STRINGS IN MANY PROGRAMMING LANGUAGES?
a) +
b) *
c) /
d) -
WHAT IS THE RESULT OF CONCATENATING THE STRINGS "HELLO"
AND "WORLD"?
a) "HelloWorld"
b) "Hello World"
c) "Hello,World"
d) "Hello-World"
IN PROGRAMMING, WHAT DATA TYPE IS TYPICALLY USED TO
REPRESENT WHOLE NUMBERS (INTEGERS)?
a) String
b) Numeric
c) Boolean
d) Character
WHICH OF THE FOLLOWING IS A BOOLEAN OPERATOR OFTEN USED
FOR LOGICAL COMPARISONS?
a) &
b) |
c) !
d) ^
ANSWERS:
1.A 2.A 3.A 4.B 5.C
TEXT PROCESSING COMMANDS OVERVIEW
Text Processing Commands:
grep, cut, awk.
Essential tools for manipulating and extracting information from text
data.
Objective:
Understand the purpose and usage of these commands in Linux.
GREP - GLOBAL REGULAR EXPRESSION PRINT
Definition:
grep searches for patterns in text files and displays matching
lines.
Basic Syntax:
Example:
CUT - REMOVING SECTIONS FROM EACH LINE
Definition:
cut removes sections from each line of a file.
Basic Syntax:
Example:
AWK - TEXT AND PATTERN PROCESSING
Definition:
awk is a versatile text-processing tool for pattern scanning and processing.
Basic Syntax:
Example:
INPUT AND OUTPUT REDIRECTION
Redirection Operators:
<: Redirects input from a file.
>: Redirects output to a file.
>>: Appends output to a file.
COMMAND CHAINING
Definition:
Command chaining involves executing multiple commands sequentially or
conditionally.
Operators:
;: Execute commands sequentially.
&&: Execute the second command only if the first one succeeds.
||: Execute the second command only if the first one fails.
EXAMPLE: SEQUENTIAL COMMAND CHAINING (;)
Explanation:
mkdir my_directory: Creates a new directory named "my_directory."
cd my_directory: Changes the current working directory to "my_directory."
ls -l: Lists the contents of the current directory in a detailed format.
Result:
These commands will be executed one after the other, regardless of whether the
previous command succeeds or fails.
CONDITIONAL COMMAND CHAINING (&&)
Explanation:
gcc my_program.c -o my_program: Compiles a C program named "my_program.c" and
creates an executable named "my_program."
./my_program: Executes the compiled program.
Result:
The second command (./my_program) will only execute if the compilation (gcc) is successful. If
the compilation fails, the second command won't be executed.
CONDITIONAL COMMAND CHAINING (||)
Explanation:
The rm non_existent_file.txt command attempts to remove a file (non_existent_file.txt).
If the file doesn't exist, the rm command will fail, and the echo "File does not exist" command
after || will be executed.
Result:
The second command (./my_program) will only execute if the compilation (gcc) is successful.
If the compilation fails, the second command won't be executed.
WHICH COMMAND IS USED FOR PATTERN MATCHING AND
SEARCHING IN A TEXT FILE IN LINUX?
a) cut
b) awk
c) grep
d) sed
WHAT DOES THE CUT COMMAND DO IN LINUX?
a) Extracts specific columns from a text file
b) Searches for patterns in a text file
c) Replaces text in a file
d) Concatenates multiple files
WHAT IS THE PRIMARY PURPOSE OF THE AWK COMMAND IN LINUX?
a) Pattern matching and searching
b) Text extraction based on delimiters
c) Replacing text in a file
d) Sorting lines in a file
TO REDIRECT THE OUTPUT OF A COMMAND TO A FILE IN LINUX,
WHICH SYMBOL IS COMMONLY USED?
a) >
b) <
c) >>
d) &>
IN LINUX, WHAT IS COMMAND CHAINING USED FOR?
a) Concatenating text files
b) Running multiple commands sequentially
c) Extracting specific columns from a text file
d) Searching for patterns in a file
ANSWERS:
1.C 2.A 3.B 4.A 5.B
SCHEDULING JOBS WITH CRONTAB
Definition:
crontab is a time-based job scheduler in Unix-like operating systems.
Syntax:
EXAMPLES
Example 1: Run a Command Every Minute
Example 2: Schedule a Daily Backup at 2 AM
Example 3: Schedule a Weekly Task on Mondays
Example 4: Run a Script on the 15th of Every Month
Example 5: Run a Command Every Hour
THANK YOU