Skip to content

Instantly share code, notes, and snippets.

@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 / rmdisk.sh
Created October 12, 2013 18:56
Force a disk offline and power it down in Linux
#!/bin/bash
# AUTHOR: Tommy Butler
#
# DESCRIPTION:
# Run this script to offline and delete a disk from your Linux system.
# It should work for most people, but if you've got an old kernel it may not.
# Unless you know what you're doing, DO NOT USE THIS SCRIPT!
#
# LICENSE: Perl Artistic License - http://dev.perl.org/licenses/artistic.html
my $start = scalar localtime;
my @records = ( 'some', 'dbi', 'fetchrow', 'hashrefs' );
$promises->{first}->then
(
sub
{
warn 'DONE WITH FIRST PROMISE';
warn 'START: ' . $start;
warn 'FINISH: ' . scalar localtime;
@tommybutler
tommybutler / promise.pl
Last active July 9, 2021 20:16
Mojo Promise Map Concept
# inside my mojo route...
my $result = $library->run_object_method_that_runs_mojo_promise_map();
if ( Scalar::Util::blessed( $result ) && $result->isa( 'Mojo::Promise' ) )
{
$c->render_later();
my $start = scalar localtime;
@tommybutler
tommybutler / map.pl
Last active July 9, 2021 20:12
library method that calls Mojo::Promise->map()
return Mojo::Promise->map
(
{ concurrency => 10 },
sub
{
my $record = $_;
my $promise = Mojo::Promise->new();
Mojo::IOLoop->subprocess->run
(
#!perl
use strict;
use warnings;
use 5.020;
my $cap = 10;
my @ints =
qw(
6.1
@tommybutler
tommybutler / mojo-email-a-pdf.pl
Last active June 26, 2020 17:35
Email a PDF with Mojolicious::Plugin::Mail, and PDF::WebKit
my $pdf = 'my-html-template-for-conversion-to-pdf'; # needs to be a .html.ep template
my $mail = 'my-template-for-the-html-email'; # needs to be a .mail.ep template
$pdf = $c->render_to_string( $pdf )->to_string();
$pdf = PDF::WebKit->new( \$pdf, %pdf_opt )->to_pdf(); # see PDF::WebKit documentation for details
$c->mail
(
mail =>
{
@tommybutler
tommybutler / get_file_types.sh
Created October 2, 2019 14:01
get unique list of file suffixes (types) in current directory tree, recursively
find . -type f | perl -nE '$_ =~ s/.*\///g ; $_ =~ m/.+\..+$/ && $_ =~ s/.*\./\./ && say $_' | sort | uniq
@tommybutler
tommybutler / storage-util-by-atime.pl
Created May 14, 2019 00:31
bracketize utilized disk by last-access time in months
#!perl
use strict;
use warnings;
use Data::Dumper;
my $last_access = {};
my $tot = 0;
my $cnt = 0;