Skip to content

Instantly share code, notes, and snippets.

mikerodionov /
Created March 15, 2023 16:35
Check Files For Empty Lines
# This scripts goes over *.txt files within specified dir
# It stops and returns exit code 1 as soon as it finds empty line within a file
# In no empty lines found exit code 0 is returned
# You can use "echo $?" command to view exit code post sh script execution
cd $dir
for f in *.txt; do
perl -lne 'exit 1 if(/^$/)' $f
if [[ $? == 1 ]]; then
echo "Inside of the loop"
mikerodionov /
Last active September 21, 2022 14:43
Scale down all Kubernetes deployments except specified
# This script will scale down all deployments except for specified in grep condition
kubectl get deploy -n NAMESPACE-NAME | grep -v 'deploymentA\|deploymentB\|deploymentC' | awk '{print $1}' | while read line; do
#echo $line
kubectl scale deploy $line --replicas=0
mikerodionov /
Created September 15, 2022 07:29
WSL Password Reset
# In elevated CMD switch WSL distro default user to root (adjust distro name as necessary)
ubuntu2204 config --default-user root
# Open WSL session - it will be opened with root user, set password for your user
passwd username
# Switch your default distro user back to your user from elevated cmd window
ubuntu2204 config --default-user username
mikerodionov /
Created September 12, 2022 09:49
Connect to a shell of a running container within Kubernetes pod
kubectl exec -n $NS --stdin --tty $POD_NAME -- /bin/sh
mikerodionov /
Created September 8, 2022 13:52
# Update DNS - set/add
az vmss update -n vmss-name --set virtualMachineProfile.networkProfile.networkInterfaceConfigurations[0].dnsSettings='{"dnsServers":["", ""]}' --resource-group rg-name
# Verify
az vmss show --resource-group rg-name --name vmss-name | grep 10.10.10.
mikerodionov /
Created September 8, 2022 07:27
Windows Terminal
# Check WT version
wt --version
mikerodionov /
Last active September 1, 2022 07:46
Aliases for kubectl & kubectx
cat <<EOF > ~/.bash_aliases
# To set permanent bash aliases create/change ~/.bash_aliases
# And refer to .bash_aliases in .bashrc
alias k='kubectl'
alias kc='k config view --minify | grep name'
alias kdp='k describe pod'
alias kd='k describe pod'
alias ke='k explain'
alias kf='k create -f'
alias kg='k get pods --show-labels'
mikerodionov /
Last active August 30, 2022 11:11
CentOS LV resize
# LVM Linux (RHEL/CentOS)
# Confirm partition type (MBR/GPT)
# Check available space
sudo pvs
# Identify LV for / - e.g. sda2 rootvg-rootlv
lsblk -f
# Check available space within VG
vgdisplay rootvg
mikerodionov / GetVMCoresPerRG.ps1
Last active August 19, 2022 14:43
Azure - Get number of cores for all VMs within a specific resource group
# Make sure to run Connect-AzAccount first
$Subscription = "SUBSCRIPTION_NAME"
$Location = "REGION_NAME"
$ResourceGroup = "RESOURCE_GROUP_NAME"
Set-AzContext -SubscriptionName $Subscription | Out-Null
$TotalCores = $null
$TotalWorkers = (Get-AzVM -ResourceGroupName $ResourceGroup -Status | Where-Object { (
$_.ProvisioningState -eq "Succeeded" ) })
foreach ($Worker in $TotalWorkers) {
mikerodionov /
Last active August 18, 2022 09:44
Extend LVM Partition with lvextend command in Linux
df -h /home/
sudo lvextend -L +31.50G /dev/mapper/rootvg-homelv
sudo resize2fs /dev/mapper/rootvg-homelv