Skip to content

Instantly share code, notes, and snippets.

@tomfanning
tomfanning / record-smart-stats.sh
Last active January 10, 2018 10:36
Noteworthy SMART stats gathering into MySQL / MariaDB / AWS Aurora / RDS
#!/bin/bash -e
# https://gist.github.com/tomfanning/2a69ba71b2371b2e6149b49d43198614
#CREATE TABLE IF NOT EXISTS `smartstats` (
# `id` int(11) NOT NULL AUTO_INCREMENT,
# `host` varchar(50) NOT NULL,
# `timestamp` datetime NOT NULL,
# `diskserial` varchar(50) NOT NULL,
# `attribute` tinyint(4) unsigned NOT NULL,
@tomfanning
tomfanning / backup-vms.ps1
Created December 6, 2017 16:36
Back up Hyper-V VMs to a network share
$errorActionPreference='Stop';
remove-item -recurse -force c:\backup\tsl.prev -ErrorAction Ignore
rename-item c:\backup\tsl c:\backup\tsl.prev
get-vm | where-object -Property Name -like 'tsl.*' | export-vm -path c:\backup\tsl;
robocopy C:\backup\TSL \\sg-81-vmhost\usb-backup\TSL *.* /mir
@tomfanning
tomfanning / install-freepbx.sh
Last active February 19, 2024 11:50
FreePBX installation script for CentOS 7 / AWS - two short non-interactive parts
#!/bin/bash -e
# set up a swapfile
dd if=/dev/zero of=/1GB.swap bs=1024 count=1048576
mkswap /1GB.swap
chmod 0600 /1GB.swap
swapon /1GB.swap
echo "
/1GB.swap none swap sw 0 0" >> /etc/fstab
echo "
@tomfanning
tomfanning / userdata.sh
Last active April 24, 2024 21:00
AWS EC2 userdata script to set root pw, allow pw logon, auto updates, and set selinux permissive.
#!/bin/bash -e
rootpw="mypassword"
cat /etc/ssh/sshd_config | sed "s/PasswordAuthentication no/PasswordAuthentication yes/" | sed "s/#PermitRootLogin yes/PermitRootLogin yes/" > /etc/ssh/sshd_config
echo "
MaxAuthTries 10" >> /etc/ssh/sshd_config
systemctl restart sshd
echo root:$rootpw | chpasswd
@tomfanning
tomfanning / iscsi-target.txt
Created November 15, 2017 15:12
Create an iSCSI target on ZFS on CentOS 7
zfs create -o volblocksize=32k -V 10G tslpool/iscsi1
zfs set sync=disabled tslpool/iscsi1
targetcli
block/ create name=block_backend dev=/dev/zvol/tslpool/iscsi1
cd /iscsi
create iqn.2017-11.com.mydomain.ad.zfstest:iscsidisk1
cd /iscsi/iqn.2017-11.com.mydomain.ad.zfstest:iscsidisk1/tpg1/acls
# create acl with the initiator (client) name here, not the one you just created
create iqn.1991-05.com.microsoft:dc1.ad.mydomain.com
cd iqn.1991-05.com.microsoft:dc1.ad.mydomain.com
@tomfanning
tomfanning / send-glip.ps1
Created October 31, 2017 16:59
Quick and dirty powershell-to-glip webhook function
function Send-Glip {
$msg = $args[0].Replace("`"", "\`"")
$body='{"body":"' + $msg + '"}'
iwr https://hooks.glip.com/webhook/webhook-guid-here -method post -ContentType application/json -body $body > out-null
}
# Usage:
# send-glip "Message to send"
@tomfanning
tomfanning / recipe.txt
Created October 26, 2017 15:55
Recipe for getting a prompt on a stock Windows EC2 instance
In userdata on the target:
<powershell>
$admin = [adsi]("WinNT://./administrator, user")
$admin.PSBase.Invoke("SetPassword", "SufficientlyC0mplexPasswordHere!")
Invoke-Expression ((New-Object System.Net.Webclient).DownloadString('https://gist.githubusercontent.com/tomfanning/19a983ad793e63d68117bd90bd57e02b/raw/8508a56fd5eb0456e2aa34a278cb7e6fbafe9dd8/configure-windows-remoting-ec2.ps1'))
</powershell>
Also ensure a security group is applied which opens port 5986.
@tomfanning
tomfanning / configure-windows-remoting-ec2.ps1
Created October 26, 2017 15:52
Script to configure a stock AWS Windows AMI to enable remoting - cert CN set to public DNS name
#Requires -Version 3.0
# Configure a Windows host for remote management with Ansible
# -----------------------------------------------------------
#
# This script checks the current WinRM (PS Remoting) configuration and makes
# the necessary changes to allow Ansible to connect, authenticate and
# execute PowerShell commands.
#
# All events are logged to the Windows EventLog, useful for unattended runs.
@tomfanning
tomfanning / instructions.txt
Created October 25, 2017 16:01
Installing an SSH server on Windows
From cmd.exe:
@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
choco install mls-software-openssh -y
If your pageant offers lots of SSH keys, you will get an error "too many authentication failures"
To overcome, in C:\Program Files\OpenSSH\etc\sshd_config, set:
MaxAuthTries 10
restart OpenSSHd service
# unproven as yet
# initial backup
zfs snapshot -r tank1@backup
zfs send -R tank1@backup | zfs receive -vF usb5tb
# incrementals
# it is optional to delete snapshots - in which case just create a snapshot with name base on time.
zfs rename -r tank1@backup tank1@previous_backup # rename the "old" snapshot