Saturday, September 29, 2018

Run any statement/command in all k8s pods with name matching a regex within a given context

#!/bin/bash -e
# runInPods.sh
# @description run any statement in all k8s pods with name matching a regex within a given context (kubectl config view ).
# @author Nestor Urquiza
# @date 20180929
#
# @example1 For my-project, in my-cluster, in pods named '*nodejs*', run the 'ps -ef | grep node' command
# ./runInPods.sh -c gke_my-project_us-east1-b_my-cluster -r nodejs -s "ps -ef | grep node"
#
# options
while [[ $# -gt 1 ]]; do
key="$1"
case $key in
-c|--context)
context="$2"
shift
;;
-r|-regex)
regex="$2"
shift
;;
-s|--statement)
statement="$2"
shift
;;
*)
# unknown
;;
esac
shift
done
# functions
function fail() {
echo $1
echo $USAGE
exit 1
}
# main
USAGE="Usage: `basename $0` (-c, --context --- from 'kubectl config view') [-r, --regex --- defaults to all)] (-s, --statement --- any valid command)"
if [ "$context" == "" ]; then
fail "Context is mandatory. Find available contexts by running 'kubectl config view'"
fi
if [ "$regex" == "" ]; then
regex=.
fi
if [ "$statement" == "" ]; then
fail "Statement is mandatory. Use any linux command you want to run in the matching pod(s)'"
fi
kubectl config use-context $context
command="cat <("
for line in $(kubectl get pods | \
grep "$regex" | grep Running | awk '{print $1}'); do
command="kubectl exec -i $line -- $statement"
echo "Running $statement in $line"
eval "$command"
done
view raw runInPods.sh hosted with ❤ by GitHub

Linux terminal sudden indentation?

stty opost
# press enter twice after typing command

Monday, September 10, 2018

MAC OSX MongoDB Installation

# select one of available versions
brew search mongodb
# install
brew install mongodb@3.6
# add executable to your path
echo 'export PATH="/usr/local/opt/mongodb@3.6/bin:$PATH"' >> ~/.bash_profile
. ~/.bash_profile
# create db path
sudo mkdir -p /data/db
sudo chown -R `id -un` /data/db
# run mongod
mongod
view raw mongodb hosted with ❤ by GitHub

Friday, September 07, 2018

Ubuntu MongoDB Installation

# Mongo 3
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv BC711F9BA15703C6
echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3-4.list
sudo apt-get update
sudo apt-get install -y mongodb-org=3.0.16 mongodb-org-server=3.0.16 mongodb-org-shell=3.0.16 mongodb-org-mongos=3.0.16 mongodb-org-tools=3.0.16
echo "mongodb-org hold" | sudo dpkg --set-selections
echo "mongodb-org-server hold" | sudo dpkg --set-selections
echo "mongodb-org-shell hold" | sudo dpkg --set-selections
echo "mongodb-org-mongos hold" | sudo dpkg --set-selections
echo "mongodb-org-tools hold" | sudo dpkg --set-selections
sudo service mongod start
sudo tail -f /var/log/mongodb/mongod.log
# Or use something like the below to run it in the terminal directly and even specify any database of your choice
mongod --dbpath /home/<user>/Downloads/lms_local_mongo_data/
$ Mongo 4
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4
echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list
sudo apt-get update
sudo apt-get install -y mongodb-org=4.0.10 mongodb-org-server=4.0.10 mongodb-org-shell=4.0.10 mongodb-org-mongos=4.0.10 mongodb-org-tools=4.0.10
echo "mongodb-org hold" | sudo dpkg --set-selections
echo "mongodb-org-server hold" | sudo dpkg --set-selections
echo "mongodb-org-shell hold" | sudo dpkg --set-selections
echo "mongodb-org-mongos hold" | sudo dpkg --set-selections
echo "mongodb-org-tools hold" | sudo dpkg --set-selections
sudo service mongod start
sudo tail -f /var/log/mongodb/mongod.log
# Or use something like the below to run it in the terminal directly and even specify any database of your choice
mongod --dbpath /home/<user>/Downloads/lms_local_mongo_data/

Sunday, September 02, 2018

If your linux terminal clipboard stops working

Manipulate the X selection with xsel command. In this case "clean clipboard":
alias clear-xsel='xsel -cp && xsel -cs && xsel -cb \
        && echo Primary, secondary and clipboard X selections were cleared'

Followers