Skip to content

Instantly share code, notes, and snippets.

View cupracer's full-sized avatar

Thomas Schulte cupracer

  • NRW, Germany
  • 03:16 (UTC +02:00)
View GitHub Profile
@cupracer
cupracer / curl.php
Created March 20, 2018 10:00
Simple PHP script to run a curl command
<?php
$url = 'https://www.google.de';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
$response = curl_exec($ch);
@cupracer
cupracer / httpd.conf
Created April 10, 2020 07:59
Apache config to redirect all requests to a static page (status 503 - Service Unavailable)
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}/static.html -f
RewriteCond %{SCRIPT_FILENAME} !static.html
RewriteRule ^.*$ /static.html [R=503,L]
ErrorDocument 503 /static.html
@cupracer
cupracer / monitor-logfile-and-react-on-hits.sh
Last active June 10, 2022 08:28
Simple logfile monitor which counts occurrences of a string and reacts after n hits
#!/bin/bash
USE_SYSTEMD_JOURNAL=0
LOGFILE=/var/log/snapper.log
WAIT_FOR_HITS=3
SEARCH_TERM="test 123"
################
if [ ${USE_SYSTEMD_JOURNAL} -lt 1 ] && ! [ -r ${LOGFILE} ]; then
@cupracer
cupracer / dead-man-switch.sh
Last active August 26, 2020 14:20
setup a watchdog which triggers a kernel panic if the script gets stuck
#!/bin/bash
KERNEL_MODULE=softdog
WATCHDOG_DEVICE=/dev/watchdog
LOGFILE=/deadmancheck.log
WATCHDOG_TIMEOUT=30
SLEEPTIMER=3
####
@cupracer
cupracer / list-rpms-with-doc-excluded.sh
Created November 17, 2020 13:23
List all installed RPM packages which were installed without docs
for i in $(rpm -qa);
do
rpm -qs $i | grep -q "not installed" && test $(rpm -qlc $i | wc -l) -ne 0 && echo $i
done
@cupracer
cupracer / timestamp.py
Last active April 20, 2021 09:13
Calculate timestamps by adding or subtracting seconds
#!/usr/bin/python3
import sys
import re
from datetime import datetime, timedelta
if not len(sys.argv) == 4:
print('\n * usage: ' + sys.argv[0] + ' %Y-%m-%d-%H:%M[:%S] add|sub #seconds\n')
exit(1)
@cupracer
cupracer / dates.sh
Created July 26, 2021 18:34
Generate dates in Bash
#!/bin/bash
# Simple one-liner to increase and print dates. To be used in scripts.
# Current command starts today and prints next 100 dates.
#
# Output:
# 2021-07-26
# 2021-07-27
# 2021-07-28
# ...
@cupracer
cupracer / test.php
Created August 24, 2021 20:49
Don't compare float values in PHP!
<?php
$a = 0.20;
// Test 1:
$b = 1 - 0.80; // 0.20
if ($a == $b) {
echo "true";
@cupracer
cupracer / read-udev-multipath-events.py
Last active June 13, 2022 09:27
Read specific multipath events from systemd-udevd.service via systemd-journal
#!/usr/bin/env python3
#
# use with:
# udevadm control --log-level=debug
#
# example output:
#
# ACTIVE: 0, STARTED: 142, SUCCEEDED: 142, BURSTS: 0, LONGEST: 0.366994 secs (device: dm-18, start: 11:22:09.099568, end: 11:22:09.466562)
# Burst detected. Resetting.
@cupracer
cupracer / simple_image_walk.sh
Created August 23, 2022 08:49
Get all steps used during container image building (aka Dockerfile instructions)
#!/bin/bash
IMAGE=$1
PARENT=$IMAGE
declare -a RESULTS REV_RESULTS
while [ -n "${PARENT}" ]; do
JSON=$(docker inspect $PARENT |jq .)
RESULTS+=("$(echo $JSON | jq '.[0]'.ContainerConfig.Cmd)")