Skip to content

Instantly share code, notes, and snippets.

View mario21ic's full-sized avatar
👋
Open to work

Mario IC mario21ic

👋
Open to work
View GitHub Profile
@mario21ic
mario21ic / Jenkinsfile
Created August 29, 2017 19:17
Function to get the last successfull build in Jenkins
def lastSuccessfullBuild(build) {
if(build != null && build.result != 'FAILURE') {
return build.number;
} else {
lastSuccessfullBuild(build.previousBuild);
}
}
@mario21ic
mario21ic / packer-ami-id
Created August 16, 2017 23:10 — forked from danrigsby/packer-ami-id
Get AMI ID from a packer build
packer build packer.json 2>&1 | sudo tee output.txt
tail -2 output.txt | head -2 | awk 'match($0, /ami-.*/) { print substr($0, RSTART, RLENGTH) }' > sudo ami.txt
@mario21ic
mario21ic / packer-ami-id
Created August 16, 2017 23:10 — forked from danrigsby/packer-ami-id
Get AMI ID from a packer build
packer build packer.json 2>&1 | sudo tee output.txt
tail -2 output.txt | head -2 | awk 'match($0, /ami-.*/) { print substr($0, RSTART, RLENGTH) }' > sudo ami.txt
@mario21ic
mario21ic / Jenkinsfile.groovy
Created August 15, 2017 19:49 — forked from Faheetah/Jenkinsfile.groovy
Jenkinsfile idiosynchrasies with escaping and quotes
node {
echo 'No quotes in single backticks'
sh 'echo $BUILD_NUMBER'
echo 'Double quotes are silently dropped'
sh 'echo "$BUILD_NUMBER"'
echo 'Even escaped with a single backslash they are dropped'
sh 'echo \"$BUILD_NUMBER\"'
echo 'Using two backslashes, the quotes are preserved'
sh 'echo \\"$BUILD_NUMBER\\"'
echo 'Using three backslashes still results in preserving the single quotes'
export CLUSTER_DNS=[...]
export CLUSTER_IP=[...]
ssh -i workshop.pem docker@$CLUSTER_IP
docker container run -d --name jenkins -p 8080:8080 jenkins:alpine
docker container ls # Wait until it is up and running
export CLUSTER_DNS=[...]
export CLUSTER_IP=[...]
ssh -i workshop.pem docker@$CLUSTER_IP
docker container run -d --name jenkins -p 8080:8080 jenkins:alpine
docker container ls # Wait until it is up and running
@mario21ic
mario21ic / subprocessdemote.py
Created June 26, 2017 23:39 — forked from sweenzor/subprocessdemote.py
Run python subprocess(es) as another user
#!/usr/bin/env python
import os
import subprocess
# > python subprocessdemote.py
# > sudo python subprocessdemote.py
def check_username():
@mario21ic
mario21ic / socat_examples
Created June 23, 2017 17:42
Examples for using socat (and filan)
// Examples for using socat (and filan)
//"$" means normal user, "#" requires privileges, "//" starts a comment
///////////////////////////////////////////////////////////////////////////////
// similar to netcat
// connect to 10.1.1.1 on port 80 and relay to and from stdio
@mario21ic
mario21ic / apache
Created June 4, 2017 19:07
Monit files to configuration: apache, httpd, nginx, mysql and sshd
check process apache with pidfile /run/apache2.pid
start program = "/etc/init.d/apache2 start" with timeout 60 seconds
stop program = "/etc/init.d/apache2 stop"
@mario21ic
mario21ic / user.data.get.latest.sh
Created May 24, 2017 17:44
Script to use in user data to aws ec2
#!/bin/bash
BUCKET="mybucket.deploy"
ENVIRONMENT="dev"
LATEST="/tmp/latest.zip"
APP_DIR="/var/www/web"
latest=$(aws s3 ls s3://$BUCKET/$ENVIRONMENT/ --recursive | sort | tail -n 1 | awk '{print $4}')
aws s3 cp s3://$BUCKET/$latest $LATEST
sudo mkdir -p $APP_DIR && unzip -qo $LATEST -d $APP_DIR
rm -f $LATEST