Skip to content

Instantly share code, notes, and snippets.

View carlosrodlop's full-sized avatar
🇪🇸
Working from home

Carlos Rodriguez Lopez carlosrodlop

🇪🇸
Working from home
View GitHub Profile
@carlosrodlop
carlosrodlop / systemAndProcess.sh
Created February 23, 2023 13:14
systemAndProcess.sh
# Get System identification
uname -a
cat /etc/*release*
# Change to root (no password)
sudo su
# Packages
## Debian/Ubuntu
apt-cache search kubernetes # Search by names
@carlosrodlop
carlosrodlop / commands.cmd
Created February 23, 2023 13:09
Windows Commands
@echo off
REM List task and find a particular one
tasklist | FIND "agent.jar"
REM get host IP
ipconfig
REM Equivalent to "curl URL and get the output in a file" in linux
Invoke-WebRequest -Uri 'http://x.x.x.x:xxxx/computer/NPERMG382/slave-agent.jnlp?encrypt=true' -OutFile c:\temp\jnlp.txt
REM Equivalent to "cat a file passed as variable" in linux
type %THEFILE%
REM Kill Java Process
@carlosrodlop
carlosrodlop / network.sh
Last active January 31, 2023 08:18
Network Troubleshooting snippets
# Check connection FROM Host > TO my-example.com (e.g. port 8443)
telnet my-example.com 8443 #It maintains a socket open to port 8443 (as example), so it can be useful to validate if there is a man a middle closing the channel Connection closed by foreign host
curl -IvL -X GET https://my-example.com #It also accepts to curl to a specific port e.g. https://my-example.com:8443
nc -z -v -w 2 my-example.com 8443 # It will tell if the port is open or not
# Check if a services is running in the Host
sudo lsof -i -P -n | grep LISTEN # Prefered method, it provides more information including the process. For extended output use sudo
netstat -pnatu | grep LISTEN
lsof -i :50001 # Check if an application is listening to specific PORT (50001)
netstat -ntpl | grep 50001 # Check if an application is listening to specific PORT (50001)
@carlosrodlop
carlosrodlop / kubectl.sh
Created January 30, 2023 14:48
kubectl snippets
################################################################
# REFERENCES:
#https://kubernetes.io/docs/reference/kubectl/cheatsheet/
################################################################
# CLUSTER
# CONTEXT: Locate your context and cluster
## List all context
kubectl config get-contexts
@carlosrodlop
carlosrodlop / helm.sh
Created January 30, 2023 12:23
Helm snippets
################################################################
# REFERENCES:
# https://helm.sh/docs/helm/
################################################################
# Add Repo to Helm
helm repo add cloudbees https://charts.cloudbees.com/public/cloudbees
helm repo update
# Search (List) for charts
helm search hub jenkins # in the public hub
@carlosrodlop
carlosrodlop / git.sh
Created January 30, 2023 12:22
Git snippets
# Revert Uncommited Changes
git reset --hard; git clean -fd
# Remove branch: local and remote
git branch -D exampleBranch; git push origin --delete exampleBranch
# Checkout remote branch
git branch -a; git checkout origin/exampleBranch; git checkout exampleBranch
# Checkout remote PR
@carlosrodlop
carlosrodlop / filesAndfolders.sh
Created January 19, 2023 11:15
Files & Folder snippets for Unix
# Find "*<Container_ID>*" files names within the <folder-example>
find <folder-example> -name "*<Container_ID>*"
# Search on docker messages folder all the messages obteined
grep "level=>:error" messages | awk -F":message=>" '{print $2}' | sort | uniq -c| sort -n
grep "level=error" messages | awk -F":msg=" '{print $1}' | sort | uniq -c| sort -n
curl -u admin:*** https://example.com/example-master/ > version.html ; cat version.html | grep jenkins_ver | awk -F"jenkins_ver" '{print $2}' | awk -F"span" '{print $1}'
# Jenkins
## Getting exiting reason for a build
for i in $(find "${JENKINS_HOME}/jobs" -name "build.xml"); do grep -H -i "exit(" "$i"; done
@carlosrodlop
carlosrodlop / docker.sh
Last active January 19, 2023 11:07
Docker snippets
# Docker daemon
## Debian/ubuntu
sudo service docker start
sudo service docker stop
##Centos/Redhat
sudo systemctl start docker
sudo systemctl stop docker
# Upload Image to DockerHub
## Login
@carlosrodlop
carlosrodlop / quietShutDownBeforeDrain.sh
Created December 22, 2021 12:59
Bash script to move Jenkins apps to "quietmode" for a specific time passed as parameter before draining node of your CI k8s cluster
#!/bin/bash
set -euo pipefail
shopt -s inherit_errexit nullglob compat"${BASH_COMPAT=42}"
#Parameters
JENKINS_USER_ID=example.user
JENKINS_API_TOKEN=******
JENKINS_NS_LIST=("ns-example-1" "ns-example-2")
SLEEP_SEC=3600