Skip to content

Instantly share code, notes, and snippets.

View alioualarbi's full-sized avatar

Alioua Larbi alioualarbi

  • Everflow
  • Montréal, Québec, Canada
  • 18:02 (UTC -12:00)
View GitHub Profile
@alioualarbi
alioualarbi / expbackoff.sh
Created December 18, 2022 19:53 — forked from nathforge/expbackoff.sh
Exponential backoff in Bash
expbackoff() {
# Exponential backoff: retries a command upon failure, scaling up the delay between retries.
# Example: "expbackoff my_command --with --some --args --maybe"
local MAX_RETRIES=${EXPBACKOFF_MAX_RETRIES:-8} # Max number of retries
local BASE=${EXPBACKOFF_BASE:-1} # Base value for backoff calculation
local MAX=${EXPBACKOFF_MAX:-300} # Max value for backoff calculation
local FAILURES=0
while ! "$@"; do
FAILURES=$(( $FAILURES + 1 ))
if (( $FAILURES > $MAX_RETRIES )); then
# Notify Slack - Send notifications to a Slack Channel
# Copyright (C) 2016 Gustavo Arjones (@arjones)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# Full blog post here: http://arjon.es/2016/09/15/be-notified-on-slack-when-a-long-process-finishes/
#
@alioualarbi
alioualarbi / env-multiple.cloudbuild.yaml
Created November 9, 2022 18:49 — forked from davidstanke/env-multiple.cloudbuild.yaml
Persist multiple environment variables to subsequent Cloud Build steps
steps:
- id: "Store Values"
name: gcr.io/cloud-builders/curl
entrypoint: /bin/bash
args:
- -c
- |
# store multiple values as environment variables
# name all values with a common prefix (we'll use "build_")
export build_firstname="Robin" &&
@alioualarbi
alioualarbi / gke-backup-test.sh
Created November 9, 2022 17:09 — forked from mikesparr/gke-backup-test.sh
Testing out backup and failure / restore scenarios with Google Kubernetes Engine (GKE) Backup features
#!/usr/bin/env bash
#####################################################################
# REFERENCES
# - https://cloud.google.com/kubernetes-engine/docs/add-on/backup-for-gke/concepts/backup-for-gke
# - https://cloud.google.com/kubernetes-engine/docs/add-on/backup-for-gke/how-to/install
#####################################################################
export PROJECT_ID=$(gcloud config get-value project)
export PROJECT_USER=$(gcloud config get-value core/account) # set current user
@alioualarbi
alioualarbi / gke-gce-cloud-armor-lb.sh
Created October 24, 2022 16:03 — forked from pydevops/gke-gce-cloud-armor-lb.sh
Example Cloud Armor policies protecting Google HTTPS Global Load Balancer in front of GCE instance group and GKE cluster
#!/usr/bin/env bash
# REF: https://cloud.google.com/armor/docs/integrating-cloud-armor#with_ingress
# REF: https://cloud.google.com/armor/docs/configure-security-policies
# REF: https://cloud.google.com/iap/docs/load-balancer-howto
# REF: https://cloud.google.com/sdk/gcloud/reference/compute/url-maps/add-path-matcher
# REF: https://cloud.google.com/load-balancing/docs/https/setting-up-url-rewrite
export PROJECT_ID=$(gcloud config get-value project)
export PROJECT_USER=$(gcloud config get-value core/account) # set current user
@alioualarbi
alioualarbi / istio-gke-tls-example.sh
Created October 24, 2022 15:53 — forked from pydevops/istio-gke-tls-example.sh
Example GKE ingress with TLS certificate for secure traffic to backend Istio ingress gateway
#!/usr/bin/env bash
export PROJECT_ID=$(gcloud config get-value project)
export PROJECT_USER=$(gcloud config get-value core/account) # set current user
export PROJECT_NUMBER=$(gcloud projects describe $PROJECT_ID --format="value(projectNumber)")
export IDNS=${PROJECT_ID}.svc.id.goog # workflow identity domain
export GCP_REGION="us-west1"
export ISTIO_VERSION="1.9.1"
@alioualarbi
alioualarbi / gist:74ae00614ca38e9419379634f3387285
Created May 23, 2022 03:52 — forked from jyap808/gist:8703450
Resume another user's screen session

The problem: Being root you would like to resume another user's screen session. Let the user be A.

You 'become' him by

su A -

or

sudo su - A
@alioualarbi
alioualarbi / gist:349ca3ae2d3d27a22f106c67a6562f0d
Created February 8, 2022 19:34 — forked from djangofan/gist:3113588
Cron job script to give a disk space usage alert email
#!/bin/sh
# this script was initially written for Redhat/CentOS
# file is /etc/cron.daily/diskAlert.cron
# requires enabling outgoing sendmail from localhost to a valid
# smtp server, which is usually disabled by default
ADMIN="jausten@adomain.com,another@adomain.com"
THRESHOLD=90
df -PkH | grep -vE '^Filesystem|tmpfs|cdrom|media' | awk '{ print $5 " " $6 }' | while read output;
do
@alioualarbi
alioualarbi / clouddlp_deidentify_with_fpe.sh
Created September 30, 2020 16:00 — forked from mdelotavo/clouddlp_deidentify_with_fpe.sh
Uses the Google Data Loss Prevention API to de-identify sensitive data in a string using Format Preserving Encryption (FPE).
# https://cloud.google.com/kms/docs/quickstart
# https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/dlp/deid.py
# https://cloud.google.com/docs/authentication/production
gcloud kms keyrings create clouddlp --location global
gcloud kms keys create dlp_deidentify_fpe --location global \
--keyring clouddlp --purpose encryption
gcloud kms keys list --location global --keyring clouddlp