Skip to content

Instantly share code, notes, and snippets.

View MParvin's full-sized avatar

Mohammad Parvin MParvin

View GitHub Profile
@MParvin
MParvin / ssh_keys_manager.sh
Created November 19, 2022 15:47
This script does is to add or remove the ssh keys of a github user to/from the authorized_keys file.
#!/bin/bash
add_ssh_keys(){
github_username=$1
IFS=$'
'
# Iterate over all keys in the github account
for key in $(curl -sSL github.com/$github_username.keys)
do
@MParvin
MParvin / konfig_merger.sh
Last active February 22, 2025 10:50
Merge kubeernetes cube config files into a single file.
#!/bin/bash
show_usage() {
echo "Usage: $0 <config1> <config2> ..."
echo "This script will merge config1, config2, ... into a single config file in current directory"
echo "The merged config file will be named as 'merged-kubeconfig'"
echo "You can copy the merged config file to ~/kube/config to use it as your default kubeconfig"
}
if [ $# -lt 2 ]; then
show_usage
@MParvin
MParvin / certbot_dns.sh
Created December 31, 2022 11:59
Certbot DNS script, This script is used to generate a certificate using DNS challenge.
#!/bin/bash
if ! [ -x "$(command -v certbot)" ]; then
echo 'Error: certbot is not installed.' >&2
exit 1
fi
if [ -z "$1" ]; then
echo "Usage: $0 domain_name"
exit 1
@MParvin
MParvin / get-image.sh
Created January 3, 2023 08:51
This script will pull an image from the public docker registry and push it to your private registry
#!/bin/bash
private_registry="registry.example.com:5000"
if [ -z "$1" ]; then
echo "Usage: $0 <image_name>"
exit 1
fi
image_name=$1
@MParvin
MParvin / manual_logrotate.sh
Created June 30, 2023 11:47
To manually rotate log files
#!/bin/bash
if [ -z $1 ]
then
echo -e "Usage is: ./main.sh PATH_TO_FILE\nExample: ./main.sh /var/log/nginx/access_log"
exit 1
fi
file=$1
@MParvin
MParvin / kind-cluster.yml
Created July 2, 2023 16:23
Kind cluster config that creates Two masters and Three workers, also mount a path from host to containers for development environment
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: control-plane
- role: worker
- role: worker
- role: worker
extraMounts:
- hostPath: /mnt/kind
@MParvin
MParvin / ssh_tunnel.service
Last active July 13, 2025 08:03
SSH tunnel systemd service
[Unit]
Description=SSH Tunnel
After=network.target
[Service]
Type=forking
EnvironmentFile=/etc/default/ssh_tunnel
ExecStart=/usr/bin/ssh -fN -D "$SOCKS_PORT" -i "$SSH_KEY" -o ServerAliveInterval=60 -o ExitOnForwardFailure=yes "$USER"@"$SSH_SERVER"
ExecStartPost=/bin/bash -c "/usr/bin/curl --silent --fail --max-time 10 -x socks5h://localhost:$SOCKS_PORT http://ifconfig.me/ip || /bin/kill -9 -- $MAINPID"
ExecReload=/bin/kill -1 -- $MAINPID
ExecStop=/bin/kill -9 -- $MAINPID
@MParvin
MParvin / kubectl_2_ssh.sh
Created July 10, 2023 07:32
Adding servers IP address from kubectl to ssh config file
#!/bin/bash
if [ -z "$1" ]
then
user_name=root
else
user_name=$1
fi
IFS='
@MParvin
MParvin / check_logstash.sh
Created October 8, 2023 14:16
Check logstash working
#!/bin/bash
command -v nc 2>&1 >/dev/null
if [[ "$#" < "2" ]]
then
echo "Usage: $0 LOGSTASH_ADDRESS LOGSTASH_PORT"
exit 1
fi
LS_IP=$1
@MParvin
MParvin / check_shecan_pro.sh
Created July 21, 2024 16:00
Check shecan pro
#!/bin/bash
echo "Checking resolv.conf"
python3 -c '
import subprocess
shecan_ips = ("178.22.122.101" "185.51.200.1")
resolver_list = []
with open("/etc/resolv.conf", "r") as f: