0% found this document useful (0 votes)
0 views4 pages

Linux 002 Overview

The document provides a step-by-step guide for creating an EC2 instance in AWS and writing Linux batch shell scripts using MobaXterm. It includes instructions for launching an instance, connecting via SSH, and writing and executing shell scripts. Additionally, it covers useful commands and techniques such as piping in Bash.

Uploaded by

John Brown
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views4 pages

Linux 002 Overview

The document provides a step-by-step guide for creating an EC2 instance in AWS and writing Linux batch shell scripts using MobaXterm. It includes instructions for launching an instance, connecting via SSH, and writing and executing shell scripts. Additionally, it covers useful commands and techniques such as piping in Bash.

Uploaded by

John Brown
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

LANDMARK SOFTWARE SOLUTIONS

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.

</> Writing Linux Batch Shell Scripts </>


Once connected to your EC2 instance, you can create and execute shell scripts using
a text editor like nano, vim or vi.
a. Here's a basic example of a shell script that prints "Hello, World!":

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:

c. </> To run a bash shell script: </>


 Start with a dot (.)
 Followed by /
 Then scriptName.sh
Syntax: ./scriptName.sh

d. Additional tips for writing shell scripts:


 Use comments to explain your code (#).
 Use variables to store values.
 Use conditional statements (if, else, elif) and loops (for, while).
 Pipe output from one command to another.
 Use the set -e option to exit the script on errors.

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 (|).

Syntax: command1 | command2

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

You might also like