Skip to main content

Posts

AWS Command line Tasks : Create EC2 instance and EC2 instance with 500GB root volume.

To create an EC2 instance from command line.

aws ec2 run-instances  --image-id ami-efe09bf8 --count 1 --instance-type m4.4xlarge --key-name mysshkey --security-group-ids sg-126adasd2--subnet-id subnet-148fd971 --block-device-mapping /dev/sda1=:500:false --region us-east-1

--image-id : The AMI ID which we are going to create the instance.
--count : The number of instances that we need to create.
--instance-type : The type of EC2 instance that we are going to use it.
--key-name : The pem that we are going to use to connect to this server.
--secrutiy group : The security group this instance is getting used.
--subnet-id : The subnet in which we want the ec2 instance.
--block device mapping - device:space in gb : to terminate volume [true or false.]

To create an EC2 instance with 500GB root volume.

aws ec2 run-instances --image-id ami-efe09bf8 --block-device-mappings  '[{"DeviceName":"/dev/sda1","Ebs":{"VolumeSize":500,"DeleteOnTermination&qu…
Recent posts

AWS command line tasks - Create 500 GB EBS Volume, to attach and detach the volume

To create a volume of 500 GB
aws ec2 --region us-east-1 create-volume --size 500 --availability-zone us-east-1d --volume-type gp2

size : in GB
availability zone : This needs to be in the same availability zone as that of the instance that we are going to attach the EBS volume.

To attach an EBS volume to the ec2 instance.

aws  ec2 attach-volume --volume-id vol-9dfjhsdkfj93 --instance-id i-1234567899oasd  --device /dev/xvdb --region us-east-1

After attaching format the drive and mount it like what we do for a normal hard disk drive.

To detach an EBS volume from the ec2 instance.

aws ec2 detach-volume --volume-id vol-9dfjhsdkfj93 --region us-east-1


AWS Command line Tasks - Create SSH key pair, security group, Allow connection to a port

We need a working aws cli configured to use the following commands.

To create an SSH pem file.

aws ec2 create-key-pair --region us-east-1 --key-name mysshkey --output text > mysshkey.pem 

region :  The region in which the ssh pem file is getting created.
Here we are saving the pem file in our linux machine as the name mysshkey.pem 


Modify the permission of the pem file.

chmod 400 mysshkey.pem 

To create a security group.

aws ec2 create-security-group --region us-east-1 --group-name work_project --description "Project_for_work" --vpc-id vpc-12345 

group name - It is the name that we are going to give for the security group
description - The description that we are going to give for the security group

To allow connection to a port

aws ec2 --region us-east-1 authorize-security-group-ingress --group-id sg-12345 --protocol tcp --port 22 --cidr 10.100.0.0/16
aws ec2 --region us-east-1 authorize-security-group-ingress --group-id sg-12345 --protocol tcp --port 22 --cidr 10.150.0.0…

Bash basics for personal reference.

To add double quotes in a line which has words seperated by comma.

sed -e 's/"//g' -e 's/[^,]*/"&"/g' -i filename

To add double quotes at end of line in a file.

sed -e 's/$/"/' -i filename

To add double quotes at begining of a line in a file.

sed -e 's/^/"/' -i filename

To replace using sed when there are too many "/" forward slash is there in the line or file to be replaced.

sed -i -e 's@/home/readonly/jas/@/home/readonly/jas/testfolder/@g' zeus_script_zdp_bos.sh

In bash scripting on remote server ssh login, we could experience problems with awk print $ and `. In such situations, use cut and there will be no such issues.

To check a log file between two dates.

awk '$0 >= "Sep 26 05:01:11" && $0 <= "Sep 26 08:37:05"' logfile

To pass two objects using multiple for loop from single file.

for i in `cat names | awk '{print $1}'`; do for j in `cat names | grep $i …

High process count notification - shell script

#Author : Jaison
# Purpose : To send email to the user when a user hit a specific process count list.

process_count="$(ps -u root  -L | wc -l)"
if [ "$process_count" -gt "10000" ]; then
 Email_Body='Test"
  echo "$Email_Body" | /usr/bin/mail -s "Server $HOSTNAME Process Count : $process_count IS A LARGE VALUE FOR  USER. CHECK IMMEDIATELY. " <email_account>
fi

useradd shell script - bulk read username and password from file.

# Author : Jaison
#Purpose : Add user and set their password from the text file all.txt


file_name="all.txt"
while read user pass
do
    #useradd ${user} -p ${pass}
    useradd ${user}
    echo "${pass}" | passwd --stdin ${user}
    echo "Adding user "${user}"  with the password  "${pass}

done < $file_name

DNS - A simple explanation.

Hi All,

Let me try to throw some pebbles regarding the DNS, one of the simplest concepts on the internet, but if explained properly, it can go into a high level of complexity.

DNS is something which is used to identify the devices which are connected to the internet.Before jumping into the concept of DNS, I hope everyone who is reading this chapter is aware of IP Adress.

If not, IP Address or in short IP is a set of numbers and symbols used to identify machines connected on the internet.

So we already have IP so you might be thinking what is the need of DNS in the world??

Well, that is the problem with the humans, we are good with names but not so good with the numbers. To overcome this problem, we are using DNS.

Domain Name System in the point of view of a System Administrator is something unavoidable when it comes to hosting the websites on the server. The simple concept of how it works is explained in my propensity as shown below.

When a website is accessed on a web browser, the &…