Skip to content

Instantly share code, notes, and snippets.

View haeramkeem's full-sized avatar

@haeramkeem haeramkeem

View GitHub Profile
@haeramkeem
haeramkeem / apt-update-checksum-mismatch.sh
Last active April 11, 2022 02:10
Fixing `apt-get update` checksum mismatch problem
#!/bin/bash
# Source of this solution: https://askubuntu.com/a/1242739
sudo su -
mkdir /etc/gcrypt
echo all >> /etc/gcrypt/hwf.deny
apt-get update
@haeramkeem
haeramkeem / netstat-examples.sh
Created April 12, 2022 01:02
netstat examples
#!/bin/bash
# Check if given port is in use
netstat -an | grep ${PORT}
# Check all TCP listening port and its process name
netstat -nlpt
#!/bin/powershell
# Enable / Disable hypervisor to use WSL2 with VirtualBox
# ref: https://github.com/MicrosoftDocs/WSL/issues/798#issuecomment-1063862157
# Enable hypervisor
bcdedit /set hypervisorlaunchtype auto
# Disable hypervisor
bcdedit /set hypervisorlaunchtype off
@haeramkeem
haeramkeem / download_deb.sh
Last active April 16, 2022 12:14
Download the debian packages with all dependencies included
#!/bin/bash
# download .deb from apt
# download the packages with all dependencies included from apt
# `grep -v "i386"` will discard all dependencies with i386 architecture
# ref: https://stackoverflow.com/a/45489718
# usage:
# $1: package name (only one permitted)
# $2: package save directory path (mkdir if path not found)
function dl_deb {
@haeramkeem
haeramkeem / go_testing.sh
Created April 16, 2022 12:14
Go testing command
#!/bin/bash
go test -run __functionName__
@haeramkeem
haeramkeem / get_cur_dir_only.sh
Created April 22, 2022 15:04
Get current directory name only
#!/bin/bash
# https://stackoverflow.com/a/1371283
result=${PWD##*/} # to assign to a variable
printf '%s\n' "${PWD##*/}" # to print to stdout
# ...more robust than echo for unusual names
# (consider a directory named -e or -n)
printf '%q\n' "${PWD##*/}" # to print to stdout, quoted for use as shell input
@haeramkeem
haeramkeem / mysqldump-example.sh
Created April 25, 2022 13:35
mysqldump command example
#!/bin/bash
mysqldump -u username -p databasename > filename.sql # dump database
mysqldump -u username -p databasename tablename1 tablename2 > filename.sql #dump tables
@haeramkeem
haeramkeem / ssh_scp_example.sh
Last active April 26, 2022 02:50
ssh scp sshpass examples
#!/bin/bash
# ssh example
ssh -T -o StrictHostKeyChecking=no ${USERNAME}@${IP}
# scp example
# Remeber `scp [OPTIONS] [FROM] [TO]`
# 1) send
scp -T -o StrictHostKeyChecking=no -r ${DIRECTORY} ${USERNAME}@${IP}:${PATH}
# 2) receive
@haeramkeem
haeramkeem / bash_script_stdin.sh
Created April 27, 2022 06:10
bash script stdin
#!/bin/sh
# ref: https://stackoverflow.com/a/28786207
cat -
@haeramkeem
haeramkeem / kubectl_get_event.sh
Created April 29, 2022 00:09
Kubectl event inquire
#!/bin/bash
kubectl get events --field-selector type=Warning # get all 'Warning' events
kubectl logs $POD_NAME