Skip to content

Instantly share code, notes, and snippets.

View alexclifford's full-sized avatar

Alex Clifford alexclifford

  • Melbourne, Australia
View GitHub Profile
@alexclifford
alexclifford / check_ip_lease.sh
Last active January 3, 2016 09:59
Hack for some dodgy DHCP leasing by dhcpd on an OpenBSD install.
#!/bin/sh
######################################################################
# Check how many unique leases are defined in /var/db/dhcpd.leases
# If there are more leases than a specified number send an email
######################################################################
# Estimate how many IP address leases there are
NUM_LEASES=$(grep ^lease /var/db/dhcpd.leases | sort -rn | uniq | wc -l | tr -d ' ')
@alexclifford
alexclifford / add_sftp_user.sh
Last active May 25, 2018 15:26
Quick script for adding a new SFTP user/directory to an existing SFTP setup on Ubuntu.
#!/bin/sh
######################################################
# Create a new SFTP user and configure their chroot
######################################################
if [ $# -ne 2 ]; then
echo "Usage: add_sftp_user.sh username password"
exit 0
fi
@alexclifford
alexclifford / patch_homeprefix_settings.diff
Created January 16, 2014 00:02
Adding support for home page namespaces in MoinMoin (see diff for full description)
# HG changeset patch
# User Paul Boddie <[email protected]>
# Date 1318183386 -7200
# Node ID 51e0575a1ee9907dd24da95c2951fce145a36518
# Parent 89882824b375c0afe55433de0e5ccc081a740c82
Added support for home page namespaces other than at the root of a site by
employing a homeprefix setting.
Changed the serveopenid action, autoadmin security policy, MyPages action and
the OpenID identity advertising in the Page class to work with home pages that
have a non-empty homeprefix.
@alexclifford
alexclifford / mysql_backup_crons
Created January 16, 2014 00:04
Quick and dirty MySQL server backups.
# MySQL database dumps
05 23 * * mon-fri root mysqldump --all-databases --events -pXXXXXXXX | gzip > /var/backup_files/mysqldumps/mysql-dbs-$(date +\%F).sql.gz
# Only keep the past 2 weeks of backups
00 23 * * * root find /var/backup_files/mysqldumps/ -mtime +14 -delete
@alexclifford
alexclifford / add_ldap_user.sh
Last active January 3, 2016 10:09
Create a new LDAP user - not tested.
#!/bin/bash
LOGDIR="/var/logs"
LOGFILE="ldap-add-user-"$(date +"%F_%H%M")".txt"
LOGPATH=$LOGDIR'/'$LOGFILE
if [ $# -ne 7 ]; then
echo "Usage: ldap_add_user.sh username firstname lastname password organisationunit maildomain authdnuser"
echo "Example: ldap_add_user.sh test.user test user hunter1 ou=Staff,dc=example,dc=com example.com cn=admin,dc=example,dc=com"
exit 0
@alexclifford
alexclifford / change_ldap_password.sh
Last active January 3, 2016 10:09
Change an LDAP user's password - not tested.
#!/bin/bash
LOGDIR="/var/logs"
LOGFILE="change-ldap-password-"$(date +"%F_%H%M")".txt"
LOGPATH=$LOGDIR'/'$LOGFILE
if [ $# -ne 3 ]; then
echo "Usage: change_ldap_password.sh username oldpassword newpassword"
exit 0
fi
@alexclifford
alexclifford / check_smb_mounts.sh
Created January 16, 2014 00:19
Example of a cron script to run before rsync-mirror to do SMB rsync's.
#!/bin/bash
# SMB mounts required for doing SMB rsync's with an rsync-mirror cron job
mount.cifs -o user=administrator,password=XXXXXXXX //test01/c$ /mnt/test01mount
@alexclifford
alexclifford / check_backuppc_pc_dirs.sh
Created January 16, 2014 00:30
Check if there are any BackupPC host backups that haven't been copied with rsync.
#!/bin/bash
PC_DIR="/var/lib/backuppc/pc"
REMOTE_SERVER=$1
SSH_PORT=$2
# SSH to a remote server to run the specified command
remote () {
ssh -p $SSH_PORT root@$REMOTE_SERVER "$@"
}
@alexclifford
alexclifford / backuppc_crons
Created January 16, 2014 00:56
Useful BackupPC crons.
# Do a check to ensure BackupPC is running, if not email root
00 12 * * * backuppc /usr/share/backuppc/bin/BackupPC_sendEmail -c
# Email a daily host summary
50 18 * * * root wget --user=backuppc --password=XXXXXXXX -O hostsummary.html http://backupserver/backuppc/index.cgi?action=summary > /dev/null 2>&1; cat hostsummary.html | mail -a "Content-type: text/html" -a "From: [email protected]" -s "Backup Summary" [email protected] > /dev/null 2>&1; rm hostsummary.html
@alexclifford
alexclifford / reformat_sd_card.sh
Created January 23, 2014 23:08
Reformat an SD card
#!/bin/sh
TARGETDISK="/dev/mmcblk0"
TARGETPARTITION="p1"
MOUNTPOINT="/media/mmcblk0p1"
# Unmount the current SD card
echo "Unmounting SD card..."
umount $MOUNTPOINT
echo ""