Skip to content

Instantly share code, notes, and snippets.

View mathse's full-sized avatar
💭
wrangling data

Mathias Decker mathse

💭
wrangling data
View GitHub Profile
@mathse
mathse / vcenter-api.md
Created July 17, 2021 17:56 — forked from kaitoii11/vcenter-api.md
Sample on how to use vCenter API
  • Authenticate to vCenter to get user credential.
# curl -k -X POST https://10.0.0.27/rest/com/vmware/cis/session -u <USERNAME>@<DOMAIN>:<PASSWORD> | jq
{
  "value": "SESSIONID"
}
  • Save the session id to a variable
# ID=SESSIONID
#!/bin/bash
domain=$1
alias=$2
./letsencrypt-auto certonly -a webroot --webroot-path /var/www/vhosts/$domain/httpdocs/ -d $domain -d www.$domain -d $alias -d www.$alias --server https://acme-v01.api.letsencrypt.org/directory
/usr/local/psa/bin/certificate -c "$domain letsencrypt" -domain $domain -key-file /etc/letsencrypt/live/$domain/privkey.pem -cert-file /etc/letsencrypt/live/$domain/cert.pem -cacert-file /etc/letsencrypt/live/$domain/fullchain.pem
/usr/local/psa/bin/site -u $domain -certificate-name "$domain letsencrypt"
## sles
modprobe vmw_pvscsi
sed -i '/^INITRD_MODULES/ s/="/="vmw_pvscsi /g' /etc/sysconfig/kernel
mkinitrd
halt
# change your scsi controller to paravirtual
## ubuntu / centos (if vmware-tools installed)
# simply change the controller to paravirtual
@mathse
mathse / gist:81a65fdd134efe61521c
Created September 29, 2015 19:59
find spamming users in mail.info log
for i in $(zgrep "postfix/smtp" mail.info* | grep "to=" | grep spamming | cut -f6 -d" " | sed 's/://g' | sort | uniq); do zgrep $i mail.info*| grep client; done
@mathse
mathse / removeUnusedViewOwnerships.ps1
Created September 17, 2015 11:05
remove unused desktop ownership in dedicated pools on VMWare Horizon View
$daysNotUsed = 7
$ignoredPools = "ignoredPools" # regex are allowed here
Add-PSSnapIn Vmware.View.Broker
Add-PSSnapIn Vmware.VimAutomation.Core
Get-DesktopVM | ?{ $_.pool_id -notmatch $ignoredPools } | ? {$_.user_displayname} | %{
$hostname = $_.hostname
$machineId = $_.machine_id
$username = $_.user_displayname.replace((Get-ADDomain).DNSRoot,(Get-ADDomain).NetBIOSName)
@mathse
mathse / gist:3ac4e465f80257fdfa0e
Created June 17, 2015 07:49
dd + progressbar
apt-get install bar
dd if=/dev/sda | bar -s xxxM > /path/to/destiantion
@mathse
mathse / gist:04c613c0aac833df86d9
Created May 24, 2015 12:17
mysqldump all mysql containers
!/bin/bash
ymlfiles=/my/docker/compose/containers
backupdir=/my/backups
for file in $(grep -lr "image: mysql" $ymlfiles/*/*.yml)
do
pw=$(grep MYSQL_ROOT_PASSWORD $file | cut -d"=" -f2)
port=$(grep 3306 $file | sed -E 's/[-" ]+([0-9]+):([0-9]+)[-" ]+/\1/')
name=$(echo $file | cut -d'/' -f5)
mysqldump -hlocalhost --protocol=tcp -uroot -p$pw -P$port --all-databases > $backupdir/db-$name-$(date +%Y-%m-%d-%H-%M-%S).sql
@mathse
mathse / gist:09d56d5aa473917d8852
Created February 12, 2015 18:39
check_mk on freenas
## you need to enable tftp under services->tftp
login via ssh
su
cd /usr/local/bin/
mount -uw /
wget -O check_mk_agent "http://git.mathias-kettner.de/git/?p=check_mk.git;a=blob_plain;f=agents/check_mk_agent.freebsd;hb=HEAD"
chmod a+x check_mk_agent
@mathse
mathse / gist:f75c096b86adc600a388
Created February 7, 2015 20:22
resize pictures (jpg) on shell
for i in $(ls -1 *.jpg | sed 's/ /;/g'); do
convert -resize 800x800 "$(echo $i | sed 's/;/ /g')" "/path/to/destiantion/$(echo $i | sed 's/;/ /g')"
done