Skip to content

Instantly share code, notes, and snippets.

View acsrujan's full-sized avatar
🏠

Srujan acsrujan

🏠
View GitHub Profile
@acsrujan
acsrujan / logrotate.conf
Created January 9, 2017 10:05
logrotate config with most of the options.
#To rotate file every 100kb, truncate the file and delete the older logs.
#This keeps only latest 100kb.
/var/logs/randomdump.log
{
size 100k
copytruncate
rotate 0
}
# Copytruncate avoids file delete and create new file.
@acsrujan
acsrujan / homebrew.yml
Created September 15, 2016 18:15
Setting up new Mac with Ansible
---
- hosts: all
tasks:
- name: Installs homebrew if not already present
command: brew -v
register: brew_check
- name: install homebrew with curl
command: /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
when: brew_check.stdout.find('command not found') > -1
@acsrujan
acsrujan / updatesudoers.yml
Created September 12, 2016 09:39
Ansible Playbook to update sudo file on ubuntu with NOPASSWD for all users with 'sudo' permission.
---
#Updates sudo file on ubuntu with NOPASSWD for all users.
- hosts: all
sudo: yes
tasks:
- name: Allow 'sudo' group to have passwordless sudo
lineinfile:
dest: /etc/sudoers
state: present
regexp: '^%sudo'
@acsrujan
acsrujan / connectionTest.sh
Last active July 18, 2016 09:18
Script to test connection of a host, port and print time taken for each connection. Output is STDOUT.
#!/bin/bash
START=`date +%s`
while [ $(( $(date +%s) - 30 )) -lt $START ]; do
{ time nc -zw30 <host ip> <port>;} |& grep real | awk '{print $2}'
done
@acsrujan
acsrujan / Instructions.md
Last active June 2, 2016 01:34
nginx load balancing nodejs

Download Repo in /var/www/ folder.

To find largest inode directory.
```for i in /*; do echo $i; find $i |wc -l; done```
@acsrujan
acsrujan / ELB-detach-attach.sh
Last active September 2, 2016 06:51
Detach and Attach a random instance to an ELB.
#!/bin/bash
LOAD_BALANCER_NAME=$1
Instance_ids_str=`aws elb describe-load-balancers --load-balancer-name $LOAD_BALANCER_NAME --query "LoadBalancerDescriptions[*].{ID:LoadBalancerName,InstanceId:Instances[*].InstanceId}[*]. {ELB:ID,InstanceId:InstanceId[*]}" --output=json |jq -r ".[].InstanceId|@csv" |sed 's/\"//g'`
IFS=',' read -a Instance_ids_array <<< "$Instance_ids_str"
for INSTANCE_ID in ${Instance_ids_array[$RANDOM % ${#Instance_ids_array[@]}]}
do
aws elb deregister-instances-from-load-balancer --load-balancer-name $LOAD_BALANCER_NAME --instances $INSTANCE_ID
aws elb register-instances-with-load-balancer --load-balancer-name $LOAD_BALANCER_NAME --instances $INSTANCE_ID
done
@acsrujan
acsrujan / rails_log_parse.sh
Last active March 17, 2016 14:09
Parses rails log file from bash to find out requests which took more than 75sec
arr=```grep -o "in.*ms" $LOG_FILE_NAME | awk '{if ($2-75000ms > 0) print $2}' | sort -r -n``` | for i in $arr; do grep -B 1 $i $LOG_FILE_NAME |awk '{print $2 FS $3}'; echo $i; done
import platform
import os
import multiprocessing
os_name = platform.system()
print ("os_name:"+os_name)
os_version = platform.version()
print ("os_version:"+os_version)
cpu_architecture = platform.architecture()[0]
@acsrujan
acsrujan / deploy_loadbalancer.sh
Last active December 4, 2016 19:11
Deploying to an ELB backed application when you have a deployment script to do on one instance.
$LOAD_BALANCER_NAME=""
Instance_ids=`aws elb describe-load-balancers --load-balancer-name $LOAD_BALANCER_NAME --query "LoadBalancerDescriptions[*].{ID:LoadBalancerName,InstanceId:Instances[*].InstanceId}[*]. {ELB:ID,InstanceId:InstanceId[*]}" --output=json |jq -r ".[].InstanceId|@csv"`
for $INSTANCE_ID in ${Instance_ids[@]}:
do
private_ip=`aws ec2 describe-instances --instance-id $id |jq -r '.Reservations[].Instances[] | .PrivateIpAddress'`
aws elb deregister-instances-from-load-balancer --load-balancer-name $LOAD_BALANCER_NAME --instances $INSTANCE_ID
`ssh $username@$private_ip` < deployment_script.sh
aws elb register-instances-with-load-balancer --load-balancer-name $LOAD_BALANCER_NAME --instances $INSTANCE_ID
done