Skip to content

Instantly share code, notes, and snippets.

View magnetikonline's full-sized avatar
💡
I have an idea!

Peter Mescalchin magnetikonline

💡
I have an idea!
View GitHub Profile
@magnetikonline
magnetikonline / README.md
Last active January 29, 2025 06:06
NSSM - the Non-Sucking Service Manager cheatsheet.
@magnetikonline
magnetikonline / README.md
Last active May 21, 2023 08:15
macOS SSH client host autocomplete.

macOS SSH client host autocomplete

Snippet for ~/.bash_profile, adding hostname autocomplete to ssh and scp.

Extracts host hints from ~/.ssh/config.

function __completeSSHHosts {
  COMPREPLY=()
 local currentWord=${COMP_WORDS[COMP_CWORD]}
@magnetikonline
magnetikonline / README.md
Last active January 14, 2018 03:39
Enable execute of bash scripts on a partition mounted with noexec.

Enable execute on partition mounted with noexec

The example situation:

  • Wish to execute a bash script at /var/foobah/myscript.sh
  • But /var/ has been mounted using noexec via /etc/fstab.
  • How to solve? Using bind mounts.

Firstly, create a directory to hold script(s), located somewhere that has exec rights, then create the target directory on noexec partition:

$ mkdir --parents /opt/magnetik/foobah
@magnetikonline
magnetikonline / mysqlslavecheck.sh
Last active December 9, 2021 15:34
Example bash script for a PRTG SSH script sensor - this one for MySQL slave to master checks.
#!/bin/bash
# query MySQL for slave replication status
# note: requires [~/.my.cnf] to be present a populated with valid MySQL password
mysql \
--batch \
--user root \
--execute "SHOW GLOBAL STATUS LIKE 'Slave_running';" | \
tail --lines 1 | grep --extended-regexp --quiet "^Slave_running\tON$"
@magnetikonline
magnetikonline / README.md
Last active September 12, 2023 05:06
Bash if conditions with functions().

Bash if conditions with functions()

Some examples of calling bash functions in if; then; fi conditionals - both functions that echo and return.

#!/bin/bash -e

function functionOne {
	echo -n "$1 - $2"
}
@magnetikonline
magnetikonline / README.md
Last active July 19, 2024 18:48
Install Parallels version 10/11/12/13 tools on Ubuntu server guest.

Install OSX Parallels version 10/11/12/13 tools on Ubuntu server guest

Have tested these instructions successfully under Ubuntu 16.04LTS and 14.04LTS.

  • Create Ubuntu server instance under Parallels (obviously).
  • Start VM, goto Actions - Install Parallels Tools... to mount the ISO image.
    • Note: if this fails, or updating tools for an existing guest you can do the following:
    • Goto Devices > CD/DVD 1 > Connect Image....
    • Select the following ISO image: /Applications/Parallels Desktop/Contents/Resources/Tools/prl-tools-lin.iso.
    • This will mount the tools CD image.
@magnetikonline
magnetikonline / README.md
Last active February 25, 2018 07:15
Transfer MySQL databases between AWS RDS instances.

Transfer MySQL databases between AWS RDS instances

The situation

  • Two AWS RDS MySQL databases - moving databases from source to destination.
  • Both databases are not publicly accessible, only via an EC2 instance(s) - e.g. you have setup your security groups.
  • Can SSH to a target EC2 instance (but of course).

What it does

  • Sets up two SSH port forwards on local machine - one to source database, another to target.
  • Via calls to transferDatabase():
@magnetikonline
magnetikonline / README.md
Last active September 13, 2017 17:18
Using BFG to clean out old binary assets from Git repository.

Using BFG to clean out old binary assets from Git repository

Reference: http://rtyley.github.io/bfg-repo-cleaner/

Example

$ wget http://repo1.maven.org/maven2/com/madgag/bfg/1.11.8/bfg-1.11.8.jar
$ git clone [email protected]:org-name/repo-name.git repo-name.cleanup
$ java -jar bfg-1.11.8.jar --delete-files '*.{gif,jpg,png}' repo-name.cleanup
$ cd repo-name.cleanup
$ git gc --prune=now --aggressive
@magnetikonline
magnetikonline / README.md
Last active October 26, 2023 05:10
AWS CLI S3 usage examples.
@magnetikonline
magnetikonline / clone.sh
Created October 21, 2014 22:57
Git shallow clone repository and any sub-modules within.
#!/bin/bash
git clone --depth 1 \
-qb $BRANCH_NAME \
$REPOSITORY_URL $TARGET_CLONE_DIR
cd $TARGET_CLONE_DIR
git submodule update -q --init --depth 1