Skip to main content

Posts

How to find java heap memory usage ?

jmap -heap 26442

Attaching to process ID 26442, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 8.1.045 9.0.4+011

using thread-local object allocation.
Garbage-First (G1) GC with 8 thread(s)

Heap Configuration:
   MinHeapFreeRatio         = 40
   MaxHeapFreeRatio         = 70
   MaxHeapSize              = 27262976000 (26000.0MB)
   NewSize                  = 5452592 (5.1999969482421875MB)
   MaxNewSize               = 16357785600 (15600.0MB)
   OldSize                  = 5452592 (5.1999969482421875MB)
   NewRatio                 = 2
   SurvivorRatio            = 8
   MetaspaceSize            = 21807104 (20.796875MB)
   CompressedClassSpaceSize = 268435456 (256.0MB)
   MaxMetaspaceSize         = 10737418240 (10240.0MB)
   G1HeapRegionSize         = 8388608 (8.0MB)

Heap Usage:
G1 Heap:
   regions  = 3250
   capacity = 27262976000 (26000.0MB)
   used     = 25738931416 (24546.557823181152MB)
   free     = 1524044584 (1453.4421768188477MB)
   94.40983778146597% used
G1 Young…
Recent posts

SSL domain expiry - bulk domain list

Hi,

This is where you need to check the SSL certificate validity for large number of domains.

domainlist.txt - The file which stores the list of domains that we need to check the SSL expiry. In this file, make sure that only one domain name is in each row.

i - The variable used here, for each iteration, each domain is checked.


for i in `cat domainlist.txt` ;
do echo "++++++++++++++++ $i ++++++++++++++++" ;
echo | openssl s_client -servername NAME -connect $i:443 2>/dev/null | openssl x509 -noout -dates ; echo --------------------------------------- ;
done


Bash basics for personal use

Replace using sed when too many slashes are there.
---------------------------------------------------
sed -i -e 's@/home/username/jas/@/home/username/jas/folder/@g' file.sh
sed -i -e 's@xxx.xxx.xxx.xxx@xxx.xxx.xxx.xxx@g' file.sh

Note : 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 add double quotes in a line which has words separated 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 beginning of a line in a file.
-----------------------------------------------------
sed -e 's/^/"/' -i filename

To check a log file between two dates.
--------------------------------------
awk '…

Add hosts entry using python

#Task : To add hosts entry to a server hosts file using python script.
# To whomsoever wondering why, this is a task which can be easily achieved via shell script, but I went forward with Python to learn python.

#Script to change the remote IP across the hosts file.
#How to run this script : python scriptname IP_that_we_need_to_set_hosts_entry
#Importing system library for passing arguments during runtime to incorporate as a jenkins job.
import sys

#The function add_remote add the remote entry to the hosts file and shows us the new entry that we added.
def add_remote():
 with open("/etc/hosts", "a") as myfile:
  myfile.write( str(entered_IP) + ' remote_server_hostname' + '\n' )
 with open("/etc/hosts", "r") as myfile:
  for line in myfile.readlines():
   if 'remote_server_hostname' in line:
    print(line)


#The function fun checks if the hosts entry for remote is added in the server. [Main function]
def fun():
 if 'remote_server_…

Shell script to add a public key to server and provide sudo privillege for that user.

#!/bin/bash
#function which contains the ssh public key for user admin to add in the servers and another function to check if key already exists
#If you want to add your user key, replace the admin with your username and add your ssh key to the section shown below.
##################################################################
admin_keyexist_check()
{
if grep -q "******ssh key goes here******admin@<serverhostname>" /home/admin/.ssh/authorized_keys; then
    echo " The ssh key already exists and is shown below...!!"
       grep -i "admin" /home/admin/.ssh/authorized_keys
    echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
    echo "Removing this shell script now...!!"
    rm -fv $0
    exit
else
    echo " The ssh key doesn't exists...!! We will add it...!!"
    echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
fi
}
####################…

EC2 instance listing using python boto3

#Purpose : To list all the AWS EC2 instances in the specified region.
#The script assume that you have a working aws cli configured with privilege to access the aws ec2 instances.
#!/usr/bin/env python
import boto3
import sys
import time
region_name = raw_input('Enter aws region for which you want to get the details of the EC2 Instance [sample : us-east-1]: ')
print (region_name, type(region_name))
time.sleep(5)
ec2 = boto3.resource('ec2', globals()['region_name'])
for instance in ec2.instances.all():
    print instance.id, instance.state, instance.private_ip_address, instance.public_ip_address, instance.tags

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…