Skip to content

Instantly share code, notes, and snippets.

@jsidhu
jsidhu / find_docker_container_from_pid.sh
Created October 6, 2017 18:39
shell script to find docker container from process id
#!/bin/bash
cpid=$1
while true; do
ppid=$(ps -o ppid= -p $cpid)
pname=$(ps -o comm= -p $ppid)
if [ "$pname" == "docker" ]; then
echo "$cpid parent $ppid ($pname)"
break
else
@jsidhu
jsidhu / gist:2ff16fe4ee734fdf358471ded60c99f4
Created July 7, 2017 20:02
Prints the name of the container inside which the process with a PID on the host is
#!/bin/bash -e
# https://stackoverflow.com/questions/24406743/coreos-get-docker-container-name-by-pid
# Prints the name of the container inside which the process with a PID on the host is.
function getName {
local pid="$1"
if [[ -z "$pid" ]]; then
echo "Missing host PID argument."
exit 1
fulload() { dd if=/dev/zero of=/dev/null | dd if=/dev/zero of=/dev/null | dd if=/dev/zero of=/dev/null | dd if=/dev/zero of=/dev/null & }; fulload; read; killall dd
Repeat the command in the curly brackets as many times as the number of threads you want to produce (here 4 threads). Simple enter hit will stop it (just make sure no other dd is running on this user or you kill it too).
https://stackoverflow.com/questions/2925606/how-to-create-a-cpu-spike-with-a-bash-command
@jsidhu
jsidhu / reflect.py
Created June 27, 2017 16:34 — forked from huyng/reflect.py
A simple echo server to inspect http web requests
#!/usr/bin/env python
# Reflects the requests from HTTP methods GET, POST, PUT, and DELETE
# Written by Nathan Hamiel (2010)
from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
from optparse import OptionParser
class RequestHandler(BaseHTTPRequestHandler):
def do_GET(self):
#!/bin/bash
HOST=$1
PORT=$2
timeout 1 bash -c "cat < /dev/null > /dev/tcp/${HOST}/${PORT}"
RESULT=$?
if [ "${RESULT}" -ne 0 ]; then
echo "Failed: ${RESULT}"
else
echo "Connected: ${RESULT}"
@jsidhu
jsidhu / ssh-retry.sh
Created March 24, 2017 06:20
simple shell script to retry ssh repeatedly till connection succeeds.
while true; do
ssh -o ConnectTimeout=1 -o ConnectionAttempts=1 $@;
RESULT=$?
if [ "${RESULT}" -eq 0 ]; then
break
fi
done
@jsidhu
jsidhu / smtp.sh
Created March 20, 2017 20:43
simple smtp test using bash /dev/tcp without telnet
D=$(date)
timeout 1 bash -c 'cat < /dev/null > /dev/tcp/smtp.mydomain.net/25'
port_25=$?
timeout 1 bash -c 'cat < /dev/null > /dev/tcp/smtp.mydomain.net/587'
port_587=$?
echo "$D Port Check result: port_25:$port_25 git:$port_587"
MAILSERVER=smtp.mydomain.net
PORT=25
@jsidhu
jsidhu / ansible_ssl_cert.yaml
Created March 15, 2017 05:14
Ansible snippet to create a self signed ssl certificate
# - name: Generate DH Params (may take several minutes!)
# command: openssl dhparam \
# -out "/data/jenkins_home/ssl/dhparam.pem" 2048
# args:
# creates: "/data/jenkins_home/ssl/dhparam.pem"
#
# - name: Generate ECC Key
# command: openssl ecparam \
# -genkey \
# -name prime256v1 \
### Keybase proof
I hereby claim:
* I am jsidhu on github.
* I am jsidhu (https://keybase.io/jsidhu) on keybase.
* I have a public key ASBlpUiQzU2mRnLU-XHgUp48K8Dh0ClDczVnZ7ATKJYQogo
To claim this, I am signing this object:
@jsidhu
jsidhu / gist:766e4e85193f89c94640495959eb5620
Created July 6, 2016 19:01
Curl post to zabbix api (api_jsonrpc.php)
curl -i -X POST -H 'Content-type:application/json' -d '{"jsonrpc":"2.0","method":"user.login","params":{ "user":"myUserName","password":"myPassword"},"auth":null,"id":0}' https://zabbix-web.symcpe.net/api_jsonrpc.php