Linux 002 Overview
Linux 002 Overview
DevOps module I–AWS Red Hat Server Administration with Linux Batch Shell
Scripting
with Engr. Kah Kissinger
</>Linux 002 – Batch shell Scripting</>
Task: Creating an EC2 Instance in AWS and Writing Linux Batch Shell Scripts on
MobaXterm
</> Creating an EC2 Instance </>
1. Log in to the AWS Management Console:
Access the AWS Management Console using your credentials.
2. Launch an EC2 Instance:
Navigate to the EC2 service.
Click on "Launch Instance."
Choose an Amazon Machine Image (AMI) based on Red Hat Enterprise
Linux.
Select an appropriate instance type based on your needs (e.g., t2.micro for
testing).
Configure instance details (network settings, key pair, security group).
Review instance launch and click "Launch."
3. Create a Key Pair:
If you don't have one, create a key pair to access your instance.
Download the key pair file (.pem) and securely store it.
Connecting to the EC2 Instance Using MobaXterm
1. Install MobaXterm:
Download and install MobaXterm on your local machine.
2. Obtain Instance Public IP:
1|Page
In the AWS EC2 console, find the public IP address of your newly launched
instance.
3. Create a New Session in MobaXterm:
Open MobaXterm.
Click on the "Session" button.
Choose "SSH" as the session type.
Enter the public IP address of your EC2 instance in the "Remote host" field.
Provide a username (usually "ec2-user" or "root").
4. Import Key Pair:
In MobaXterm, navigate to "Session" -> "SSH" -> "Authentication".
Import the .pem key file you downloaded earlier.
5. Connect to the Instance:
Click the "OK" button to establish the SSH connection.
NB: Check the use of the commands: echo and chmod above {Script AD-01}
2|Page
b. </> To create or write a bash shell script: </>
Step1: Open a new file in your preferred text editor.
Step2: Paste the script code into the file. Ensure the script start with “ #!/bin/bash ”
Step3: Save the file with a .sh extension (e.g., hello.sh).
Step4: Make the script executable:
e. Examples:
3|Page
</> Additional Commands </>
1. Piping in Bash
Piping is a powerful feature in Bash that allows you to take the output of one command and use it
as the input for another command. This is done using the pipe character (|).
Examples:
1. ls |wc – l # to list all files in a directory and then count the number of files. (note: wc –l is used
to count the number of lines or files)
2. grep “pattern” file.txt | wc - l #grepping for a pattern in a file and counting the occurrences.
3. ps aux | sort –k 3 –n | head -5 # Listing processes, sorting them by CPU usage, and selecting the
top 5.
4|Page