Javatpoint Logo
Javatpoint Logo

What is Bash Script?

Bash Script is a plain text file that contains the commands used in a command line.

Creating a Bash Script

Step 1: Creating an HTML page.

  • Create the web page in a Notepad and save it with .html extension.
Bash Script

Step 2: Creating a bucket in S3.

  • Move to the S3 service.
  • Create a bucket in S3.
Bash Script
  • Enter the bucket name.
Bash Script

  • Click on the Create button.
  • Click on the jtpbucket that you created and upload the index.html file in S3.
  • The below screen shows that index.html file has been successfully uploaded in S3.
Bash Script

Step 3: Creating an IAM Role.

  • Now, go to the main console and click on the IAM service.
Bash Script
  • We create a new Role.
  • Select EC2 service to access your AWS services on your behalf. Click on the Next.
  • Select the AmazonS3FullAccess policy, this policy gets attached to our role.
Bash Script
  • Click on the Next.
  • Enter the role details such as Role name.
Bash Script
  • Click on the create role.
  • The below screen shows that the role has been created with the name S3AdmainAccess.
Bash Script

In the above screen, the role which has been checked is a newly created role.

Step 4: Creating an EC2 instance

  • Move to the main console and click on the EC2 service.
  • Launch an Instance.
  • Choose an Amazon Machine Image. I select the Amazon Linux AMI 2018.03.0 (HVM).
  • Choose an Instance type. I choose a t2.micro type.
  • Configure the Instance details. Select the IAM Role as S3AdminAccess and keep other settings as default.
Bash Script
Bash Script

Bash scripts are added in an Advanced Details.

  • Add Storage to your instance. Root is a default volume, and I am not adding new volume.
Bash Script
  • Click on the Next.
  • Add a tag.
Bash Script
  • Configure Security group.
Bash Script

The above screen shows that we created a new security group whose name is WebServer.

  • Review and Launch.
  • Select an existing key pair or create a new key pair. I contain a key pair.
Bash Script
  • Finally, my EC2Instance has been created.
  • Open the Putty.
  • Enter your Host Name such as ec2-user@3.93.219.168.
  • Click on the auth in SSH appearing on the left side of the putty, attach the key pair.ppk file to it.
  • Run the command sudo du to reach the root level.
  • Run the command yum update -y to update an EC2 instance.
  • Run the command yum install httpd -y to install an Apache server.
  • Start the server by running the command service httpd start.
  • Move to the directory cd /var/www/html.
  • Copy all the commands that we saw till now to the Notepad file.
Bash Script

The above screen shows the bash script.

Step 5: Test the Bash Script

  • First, we delete the instance that we created.
Bash Script
  • Now we create a new instance.
  • Launch an instance.
  • Choose an Amazon Machine Language (AMI). I choose the Amazon Linux AMI 2018.03.0 (HVM).
  • Choose an Instance type. I choose a t2.micro type.
  • Configure Instance details. Set IAM Role as S3AdminAccess and paste the bash script in Advanced details.
Bash Script
  • (Optional) Add storage.
  • Add tags.
  • Configure Security Group. I select a default group.
  • Review instance launch.
  • After launching an instance, paste the public IP address to a clipboard of the web browser. You will see the output shown below:
Bash Script

We conclude that copying the data from S3 to EC2 becomes easier by using Bash scripts.


Next Topic#




Help Others, Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA