Skip to content

Instantly share code, notes, and snippets.

@tommybutler
tommybutler / backintime-alert.sh
Last active August 29, 2015 14:26
proof of concept error detection for back-in-time
#!/bin/bash
# STATUS: proof of concept. TODO: scan syslog as well, with
# forward-compatibility for systemd's journalctl syslog also
# WARNING: this may have bugs.
# CONFIGURE THIS VARIABLE ...based on BIT config file, but here
# it is hard coded for rapid prototyping
DEPTH=6
@tommybutler
tommybutler / gist:4316212118279ffa5694
Created July 24, 2015 15:45
Quickly generate a bunch files with random content
for i in `seq -f "%02g" 0 200`; do dd if=/dev/random of=${i}.test bs=1M count=1; done
@tommybutler
tommybutler / dbic_example.pl
Last active August 29, 2015 13:58
DBIx::Class Example Script
#!/usr/bin/env/ perl
use strict;
use warnings;
use 5.019;
use lib './lib';
use My::App::Schema;
@tommybutler
tommybutler / regen_dbic_schema.sh
Last active August 29, 2015 13:58
regenerate a DBIx::Class schema dump
#!/bin/bash
# skeleton code; you will need to customize to suit
# you need to set up your database and install DBIx::Class::Schema::Loader
# along with any DBIC components you use below
cd /var/projects/My/App
dbicdump -o components='["TimeStamp","PassphraseColumn"]' -o dump_directory=./lib My::App::Schema dbi:mysql:dfwpm dfwpm dfwpm '{ AutoCommit => 1 }'
@tommybutler
tommybutler / parsecommand.pl
Created February 11, 2014 20:27
parse a command invocation into the command and each of its arguments
#!/usr/bin/env perl
use strict;
use warnings;
use 5.010;
use Data::Dumper;
my $cmdstr = q{/usr/local/bin/ssh %s '/opt/something/bin/somebinary || echo "Could not execute somebinary"' -a -abc --verbose --name="tommy butler" --color="blue" --quote="'to be'" /tmp /foo};
@tommybutler
tommybutler / fixchanges.sh
Last active December 29, 2015 09:58
Fix all the bad dates in your CPAN changes file and get it right with the formal specification. This code assumes your dates aren't so mangled that they can't be parsed by Time::ParseDate
cp Changes Changesx ; grep -P '^\d' Changes | perl -MTime::ParseDate -nE 'chomp; $_ =~ s/.*?\s//; $orig = $_; $_ = Time::ParseDate::parsedate( $_ ); ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime( $_ ); $mon+=1; $year+=1900; say sprintf "%4d-%02d-%02d | $orig", $year, $mon, $mday;' | while read parseddate; do echo "$parseddate" | perl -MFile::Util -E '$file = shift @ARGV; $ftl = File::Util->new; $content = $ftl->load_file( $file ); undef $/; $swap = <>; chomp $swap; ( $good, $bad ) = split / \| /, $swap; $content =~ s/\Q$bad\E/$good/smg; $ftl->write_file( $file => $content )' Changesx; echo "$parseddate"; done
# the fixed file is in "Changesx"
@tommybutler
tommybutler / smartcheck.sh
Last active December 29, 2023 11:52
Script to quickly scan the S.M.A.R.T. health status of all your hard drive devices in Linux (at least all the ones from /dev/sda to /dev/sdzz). You need smartctl installed on your system for this script to work, and your hard drives need to have S.M.A.R.T. capabilities (they probably do).
#!/bin/bash
# install the smartctl package first! (apt-get install smartctl)
if sudo true
then
true
else
echo 'Root privileges required'
@tommybutler
tommybutler / vmware-autostarts
Last active December 8, 2023 15:50
This LSB-compliant Linux boot init script lets you auto-start VMware virtual machines on a Linux host machine running VMware Workstation. Tested successfully on Debian 7 and assumed safe for any Ubuntu or Ubuntu-based distro as well. May need some minor tweaks before you can use it on CentOS or RHEL.To use this script, follow installation instru…
#!/usr/bin/env bash
### BEGIN INIT INFO
# Provides: vmwareautostart
# Required-Start: $vmware $network $syslog
# Required-Stop: $vmware $network $syslog
# X-Start-Before:
# X-Stop-After:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
@tommybutler
tommybutler / PAR-Packer.diff
Created October 14, 2013 04:10
Patch that makes suid binaries possible for App::PAR::Packer (pp), version 1.015 It will not work if you build it with the -c or --clean option when invoking pp. Crypto filters are still in bounds though and work well. My pp helper build script is below. You don't have to use it; it just makes things easier. Substitute filenames as desired. #!/b…
Binary files PAR-Packer-1.015/a.out and PAR-Packer-1.015-patched-for-suid/a.out differ
diff -ruN PAR-Packer-1.015/myldr/boot.c PAR-Packer-1.015-patched-for-suid/myldr/boot.c
--- PAR-Packer-1.015/myldr/boot.c 2013-10-13 23:04:49.243648696 -0500
+++ PAR-Packer-1.015-patched-for-suid/myldr/boot.c 2013-10-12 20:18:12.000000000 -0500
@@ -135,7 +135,7 @@
stmpdir = par_mktmpdir( argv );
if ( !stmpdir ) DIE; /* error message has already been printed */
- rc = my_mkdir(stmpdir, 0700);
+ rc = my_mkdir(stmpdir, 0777);
@tommybutler
tommybutler / .vimrc
Created October 12, 2013 20:02
My vim settings file
" don't sacrifice functionality and features just to preserve backward compatibility with vi
:set nocompatible
" turn on syntax highlighting
:syntax enable
" if a given file type (perl, ruby, python, c, etc) has its own special auto-indentation rules, use them
:filetype plugin indent on
" turn on auto-indenting (use this if you turn off option ':filetype plugin indent on')