Skip to content

Instantly share code, notes, and snippets.

View haeramkeem's full-sized avatar

@haeramkeem haeramkeem

View GitHub Profile
#!/bin/bash
# This captures VRRP packet by tshark
tshark -nni enp0s3 -f 'vrrp'
# This also captures VRRP packet by tcpdump
# <interface> <how many packets> <verbose - v or vv> <filter>
# -i $NIC -c ${NUM} -v ${...EXPRESSIONS}
tcpdump -i enp0s3 -c 100 -v vrrp
#!/bin/bash
# Ref: https://mirwebma.tistory.com/112
# See all users
grep ${USERNAME} /etc/passwd
# Add user
adduser ${USERNAME}
@haeramkeem
haeramkeem / bash-multiline-variable.sh
Created July 7, 2022 01:06
Bash) multiline string variable
#!/bin/bash
# Ref: https://stackoverflow.com/a/15429426
read -d '' sql << EOF
select c1, c2 from foo
where c1='something'
EOF
echo "$sql"
#!/bin/bash
SAMPLE="SaMpLe"
echo ${SAMPLE^^} # This makes the string to be uppercase -> STDOUT("SAMPLE")
echo ${SAMPLE,,} # This makes the string to be lowercase -> STDOUT("sample")
@haeramkeem
haeramkeem / git-checkout-remote-branch.sh
Created July 7, 2022 00:13
Git) Checkout to remote branch
#!/bin/bash
git pull # This refeshes the local branches to fetch remote branches
git checkout origin/${BRANCH_NAME} # I donno if this necessary
git switch -c ${BRANCH_NAME}
@haeramkeem
haeramkeem / git_delete_branch.sh
Created June 29, 2022 11:08
git) Delete branch
#!/bin/bash
# Ref: https://stackoverflow.com/q/2003505
# Ref: https://stackoverflow.com/a/2003515
# Delete local-cached remote branch
git branch -rd origin/${BRANCH}
# Delete local branch
git branch -D ${BRANCH}
@haeramkeem
haeramkeem / get_primary_ip.sh
Created June 29, 2022 06:46
Get primary IPADDR
#!/bin/bash
ip -4 addr show enp0s3 | grep -oP '(?<=inet\s)\d+(\.\d+){3}'
#!/bin/bash
# Ref: https://linuxize.com/post/how-to-compare-strings-in-bash/
# Basic
[[ "string1" == "string2" ]] && echo "Equal" || echo "Not equal"
# Variable alloc
TEMP=$([[ "string1" == "string2" ]] && echo "Equal" || echo "Not equal")
@haeramkeem
haeramkeem / rhel_user_list.sh
Created June 29, 2022 05:03
RHEL get user list
#!/bin/bash
sudo cut -d: -f1 /etc/passwd
@haeramkeem
haeramkeem / systemd_cgroup_check.sh
Created June 28, 2022 00:26
Check service running on systemd cgroup
#!/bin/bash
# systemd cgroup ls
sudo systemd-cgls