Skip to content

Instantly share code, notes, and snippets.

@blackpioter
blackpioter / uid_awk.sh
Created February 8, 2021 10:46 — forked from staaldraad/uid_awk.sh
Get the uid, gid and user groups without touching /etc/passwd or running the `id` command
awk -F: 'END {print "uid:"u" gid:"g" groups:"gg}{if($1=="Uid"){split($2,a," ");u=a[1]}if($1=="Gid"){split($2,a," ");g=a[1]}if($1=="Groups"){gg=$2}}' /proc/self/status
@blackpioter
blackpioter / awk_netstat.sh
Created February 4, 2021 18:35 — forked from staaldraad/awk_netstat.sh
AWK to get details from /proc/net/tcp and /proc/net/udp when netstat and lsof are not available
# Gawk version
# Remote
grep -v "rem_address" /proc/net/tcp | awk '{x=strtonum("0x"substr($3,index($3,":")-2,2)); for (i=5; i>0; i-=2) x = x"."strtonum("0x"substr($3,i,2))}{print x":"strtonum("0x"substr($3,index($3,":")+1,4))}'
# Local
grep -v "rem_address" /proc/net/tcp | awk '{x=strtonum("0x"substr($2,index($2,":")-2,2)); for (i=5; i>0; i-=2) x = x"."strtonum("0x"substr($2,i,2))}{print x":"strtonum("0x"substr($2,index($2,":")+1,4))}'
# No Gawk
# Local
grep -v "rem_address" /proc/net/tcp | awk 'function hextodec(str,ret,n,i,k,c){
@blackpioter
blackpioter / boto3_instanceId_tagName
Created February 20, 2017 18:50
boto3_instanceId_tagName
#!/usr/bin/env python
import boto3
filter_env = {'Name': 'tag:Environment', 'Values': ['Environment']}
filter_role = {'Name': 'tag:Role', 'Values': ['Role']}
for i in ec2.instances.filter(Filters=[filter_env, filter_role]):
for tag in i.tags:
if tag['Key'] == "Name":
print (i.id + " " + tag['Value'])
@blackpioter
blackpioter / boto3_list_instances_env_role
Last active February 20, 2017 18:48
boto3_list_instances_env_role
#!/usr/bin/env python
import boto3
def list_instances_env_role(env, role):
"""
List of instances with tag:Environment and tag:Role
"""
@blackpioter
blackpioter / jenkins-backup.sh
Created November 28, 2016 15:48
jenkins-backup.sh
#!/bin/bash -xe
##################################################################################
function usage(){
echo "usage: $(basename $0) /path/to/jenkins_home jenkins.tar.gz"
}
function error_exit
{
@blackpioter
blackpioter / RPM_metadata_from_git_repo
Created November 17, 2016 14:40
RPM metadata from git repo
plugins {
id "com.palantir.git-version" version "0.5.2"
id "nebula.rpm" version "4.1.0"
}
jar {
baseName = 'PACKAGE_NAME'
try {
def details = versionDetails()
@blackpioter
blackpioter / gradle_sign_RPM_with_GPG
Created November 17, 2016 14:36
Gradle sign RPM with GPG
def isJenkinsBuild = System.getenv("BUILD_NUMBER") ?: false
if(isJenkinsBuild) {
signingKeyId = System.getenv("signingKeyId")
signingKeyPassphrase = System.getenv("signingKeyPassphrase")
signingKeyRingFile = new File(System.properties['user.home'] + '/.gnupg/secring.gpg')
}
@blackpioter
blackpioter / AWS_CS
Last active June 13, 2017 09:51
AWS CS
## AWS show instance count by type
aws ec2 describe-instances --filters Name=instance-state-name,Values=running --output json | jq ".Reservations[].Instances[].InstanceType" | sort | uniq -c | sort -n
## AWS List instances in table
aws ec2 describe-instances --output table --query 'Reservations[].Instances[].[Tags[?Key==`Name`] | [0].Value, State.Name]'
## AWS List running instances in table
aws ec2 describe-instances --output table --query 'Reservations[].Instances[].[Tags[?Key==`Name`] | [0].Value, PublicIpAddress, PrivateIpAddress , InstanceType, SubnetId ]' --filters Name=instance-state-name,Values=running
## AWS EC2 limits for account / region

Keybase proof

I hereby claim:

  • I am blackpioter on github.
  • I am blackpioter (https://keybase.io/blackpioter) on keybase.
  • I have a public key whose fingerprint is 550A 5D5B 0FF9 F873 8AE6 2257 312A D4E7 15E5 7DDC

To claim this, I am signing this object:

@blackpioter
blackpioter / mysql_CS
Created June 21, 2016 08:39
mysql CS
## mysql: show mysql host,user,passwd
SELECT Host,user,password FROM mysql.user WHERE User = "root" ORDER BY (Host="localhost") ASC ;
## mysql: set empty root password
update user set password=PASSWORD("") where User='root';
flush privileges;