Skip to content

Instantly share code, notes, and snippets.

git -c credential.helper='!f() { echo "username=${GIT_USER}"; echo "password=${GIT_TOKEN}"; }; f' fetch --all
for i in $(docker ps --format "{{.Names}}" ); do docker inspect $i | grep -i working_dir; done
@devopsy-ir
devopsy-ir / How to fire a random alert in Prometheus Alertmanager
Last active May 22, 2023 01:52
How to fire a random alert in Prometheus Alertmanager
#!/bin/bash
#https://gist.githubusercontent.com/cherti/61ec48deaaab7d288c9fcf17e700853a/raw/a69ddd1d96507f6d94059071d500fe499631e739/alert.sh
name=$RANDOM
url='https://alertmanager.example.ir/api/v1/alerts'
echo "firing up alert $name"
# change url o
curl -XPOST $url -d "[{
\"status\": \"firing\",
@devopsy-ir
devopsy-ir / port-to-container
Last active August 11, 2021 05:14
Convert port number into the container name and IP
#!/bin/bash
docker ps -q | xargs -n 1 docker inspect --format '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}} {{ .Name }}' | sed 's/ \// /' | fgrep $(iptables-save | grep -P "(--to-destination|--.port)" | grep -v "DROP" | grep -P ":\d+|--dport \d+" | fgrep $1 | fgrep -i docker | egrep "to-destination" | grep -E -o "([0-9]{1,3}[\.]){3}[0-9]{1,3}")
#Install docker-compose dynamically. Official installing way [https://docs.docker.com/compose/install/] need version obtained by your hands. But I wrote a script which obtain the latest version for you automatically.
export docker_compose_latest=$(curl -Ls -o /dev/null -w %{url_effective} https://github.com/docker/compose/releases/latest | grep -o '[^/]*$')
curl -L "https://github.com/docker/compose/releases/download/${docker_compose_latest}/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
#!/bin/bash
# Color
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
NC='\033[0m' # No Color
function red {
printf "${RED}$@${NC}\n"
}
@devopsy-ir
devopsy-ir / process-to-container
Last active May 22, 2023 01:53
A Process to docker container mapper bash script
#!/bin/bash
processPath=$(find /proc/ -name $1 2>/dev/null | tail -1)
containerID=$(cat ${processPath}/cgroup | fgrep 'pids:/docker/')
if [ -n "$containerID" ];
then
containerID=$(echo $containerID | sed -e 's#.*/docker/##g' | cut -c 1-12)
docker ps | fgrep $containerID
else
echo 'Not a docker process!'
fi