Skip to content

Instantly share code, notes, and snippets.

@sfinktah
sfinktah / mysql-restore-tables.sh
Created September 14, 2023 04:17
modular mysql backup & restore
#!/usr/bin/env bash
## For speedy use:
## mysql-restore-tables *.schema.*
## parallel -j 8 mysql-restore-table *.data.*
# MySQL server credentials
DB_USER="your_username"
DB_PASS="your_password"
DB_HOST="localhost"
@sfinktah
sfinktah / SingleInstanceLock.php
Last active September 20, 2023 11:22
single instance php lock
<?php
namespace Sfinktah\Locks;
class SingleInstanceLock {
private string $lockFile;
private int $pid;
public function __construct($scriptName = null) {
if (!$scriptName) {
@sfinktah
sfinktah / explode.sh
Last active September 20, 2023 16:36
string_between bash function
unset EXPLODED
declare -a EXPLODED
function explode
{
local c=$#
(( c < 2 )) &&
{
echo function "$0" is missing parameters
echo "$0 <delimiter> <string> <limit>"
echo "result is in EXPLODED"
@sfinktah
sfinktah / upnp.sh
Created September 28, 2023 20:22
UPNP external IP query for Asterisk in BASH
#!/usr/bin/env bash
function wan_ip_connection() {
local host=$1
result=$( curl -s "http://$host/upnp/control?WANIPConnection" \
-H 'SOAPAction: "urn:schemas-upnp-org:service:WANIPConnection:1#GetExternalIPAddress"' \
--data-binary '<?xml version="1.0"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:GetExternalI
PAddress xmlns:u="urn:schemas-upnp-org:service:WANIPConnection:1"></u:GetExternalIPAddress></s:Body></s:Envelope>'
)
REGEX='ExternalIPAddress>([0-9.]+)<'