Skip to content

Instantly share code, notes, and snippets.

View MParvin's full-sized avatar

Mohammad Parvin MParvin

View GitHub Profile
@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 / ssh_tunnel.service
Created July 3, 2023 10:44
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
ExecReload=/bin/kill -1 -- $MAINPID
ExecStop=/bin/kill -9 -- $MAINPID
Restart=always
@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 / 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 / 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 / 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 / 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 / .gitconfig
Created August 29, 2022 06:21
My git shortcuts
[user]
email = MyMail
name = Mohammad Parvin
[alias]
a = add
b = branch
s = status
c = clone
i = init
p = push
@MParvin
MParvin / manage_vpns.sh
Last active August 27, 2023 07:16
Ubuntu CLI VPN manager
#!/bin/bash
function check_status {
# $1 is VPN name
vpnName=$1
vpnIP=`nmcli connection show $vpnName | grep 'IP4.ADDRESS\[1\]' | awk '{print $2}' | cut -d'/' -f1`
vpnGateway=`nmcli connection show $vpnName | grep IP4.GATEWAY | awk '{print $2}'`
if [ "$vpnGateway" == "--" ]
then
vpnGateway=`echo $vpnIP | sed 's/\.[0-9]\{1,3\}$/\.1/'`
@MParvin
MParvin / touchpad_mng.sh
Created February 24, 2022 13:34
Touchpad manager, to enable and disable Laptop touchpad from CLI.
#!/bin/bash -x
showUsage() {
echo -e "Usage is /scripts/tochpad.sh [OPTIONS]\n\t-e To enable touch pad\n\t-d For Disable touch pad\n\t-h for this Help"
}
if [ "$#" -eq 0 ]
then
showUsage
exit 1
fi