Skip to content

Instantly share code, notes, and snippets.

Avatar

Thilo Schwarz th-schwarz

View GitHub Profile
@th-schwarz
th-schwarz / apache2AllDomains
Last active Apr 23, 2022
Fetch all domains on port 443 with aliases from apache2
View apache2AllDomains
apache2ctl -S | sed "0,/^\*:443/d" | sed -e "/ServerRoot/Q" | sed '1d' | sed 's/.*port 443 namevhost //' | sed 's/.*alias //' | awk '{print $1}' | sort
@th-schwarz
th-schwarz / ProcessBuilderWrapper.java
Last active Apr 9, 2022
A complete wrapper to the ProcessBuilder
View ProcessBuilderWrapper.java
/**
* GPL
* <br><br>
* 2 import things: <ul>
* <li>Consuming STDOUT and STDERR is necessary to avoid freezing!
* <li>If the process writes a lot of output, it has to consume. That can be done by calling <b>{@link #redirectErrorStream}</b>,
* which redirects STDERR to STDOUT!
* </ul>
*/
public class ProcessBuilderWrapper {
@th-schwarz
th-schwarz / check-mailcow-update.sh
Last active Nov 3, 2021
Script to check, if there is an update for mailcow-dockerized. In this case, an email will be sent. It's intended to use in cron jobs.
View check-mailcow-update.sh
#!/bin/bash
set -o nounset
set -o errexit
cd /opt/mailcow-dockerized && ./update.sh --check > /dev/null
exit_code=$?
[ $exit_code -eq 0 ] && echo -e "Subject:MAILCOW: Update available \n\n Update your mailcow instance please!\n" | sendmail hostmaster@your.domain
exit 0
@th-schwarz
th-schwarz / EasiestCallOfProcessBuilder.java
Last active Oct 27, 2021
The easiest call of the ProcessBuilder
View EasiestCallOfProcessBuilder.java
ProcessBuilder pb = new ProcessBuilder("ls", "-al");
pb.directory(Paths.get("/tmp").toFile());
pb.redirectErrorStream(true);
Process process = pb.start();
try (var infoStream = process.getInputStream()) {
infoStream.transferTo(System.out);
}
int exitCode = process.waitFor();
if(exitCode == 0)
System.out.println("Command successful processed.");
@th-schwarz
th-schwarz / munin-plugin-vpn-user-count.sh
Created Oct 26, 2021
munin plugin to count openvpn users
View munin-plugin-vpn-user-count.sh
#!/bin/bash
if [ "$1" = "config" ]; then
echo 'graph_title OpenVPN - count of users'
echo 'graph_args --base 1000 -l 0'
echo 'graph_vlabel count of users'
echo 'graph_category network'
echo 'graph_scale no'
echo 'run.label users'
exit 0
fi
@th-schwarz
th-schwarz / backup-mysql.sh
Last active Oct 21, 2021
Dumps every mysql database to a single file, all dump files will be zipped and redirected to the stdout.
View backup-mysql.sh
## Dumps every database to a single file, all dump files will be zipped and redirected to the stdout.
## Usage: backup-db.sh > databases.zip
##
#! /bin/bash
set -o nounset
set -o errexit
trap 'rm -rf "$BACKUP_DIR"' EXIT
BACKUP_DIR=$(mktemp -d)
MYSQL=/usr/bin/mysql