Skip to content

Instantly share code, notes, and snippets.

@tommybutler
tommybutler / perl_expect.pl
Last active December 25, 2015 06:49
Example using Perl expect to automate a shell login (Linux bash). The individual subs could/shoud be wrapped with Moose (around => subname)
#!/usr/bin/env perl
use Modern::Perl;
use 5.016;
use Expect;
use File::Util;
use Time::HiRes qw( time );
@tommybutler
tommybutler / drop_privileges.pl
Created October 12, 2013 00:18
How to drop privileges in a Perl script when initially run as root
BEGIN { # give up root identity and run as an unprivileged user ASAP
use POSIX;
my $run_as = 'user_you_want_to_run_as';
my ( $uid, $gid ) = ( getpwnam $run_as )[ 2, 3 ];
die $! unless $uid && $gid;
@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
@tommybutler
tommybutler / denyhosts-remove.sh
Created October 12, 2013 19:04
Remove an IP address ban that has been blocked by denyhosts
#!/bin/bash
# denyhosts-remove.sh
#
# AUTHOR: Tommy Butler, email: $ echo YWNlQHRvbW15YnV0bGVyLm1lCg==|base64 -d
# VERSION: 1.0
#
# SUMMARY:
# Use this script to Remove an IP address ban that has been errantly blacklisted
# by denyhosts - the ubiquitous and unforgiving brute-force attack protection
@tommybutler
tommybutler / coretemp.sh
Created October 12, 2013 19:08
Monitor CPU Core temperature in Linux on the command line
# add this to your .bashrc
function coretemp {
/usr/bin/clear;
while : ; do
/usr/bin/sensors | /bin/grep ^Core | while read x; do
@tommybutler
tommybutler / iloggedin.sh
Created October 12, 2013 19:13
See this page for details and usage instructions: http://www.atrixnet.com/send-an-email-when-someone-logs-in/
#!/bin/bash
RECIPIENT="[email protected]";
PREFIX="LOGIN ALERT!";
REMOTEIP=$(/bin/echo $SSH_CLIENT | /usr/bin/awk '{ print $1 }');
TIME=$(/bin/date +'%r, %D');
HOST=$(/bin/hostname -f);
if [[ "$REMOTEIP" == "" ]]; then
REMOTEIP='localhost';
fi
@tommybutler
tommybutler / .bashrc
Last active December 25, 2015 09:29
I source this file from the last line in my .bashrc. I name it .profile-custom and put it in my home directory
shopt -s checkwinsize
export PS1="\n[\[\e[1;37m\]\u\[\e[0m\]@\[\e[1;34m\]\H\[\e[0m\]] [\[\e[1;33m\]\d, \t\[\e[0m\]] [\[\e[1;31m\]\!\[\e[0m\]]\n\[\e[1;31m\]\[\e[0m\][\[\e[1;37m\]\w\[\e[0m\]]\n\[\e[1;37m\]\\$\[\e[0m\] "
export HISTTIMEFORMAT='%F %T '
export HISTCONTROL=ignoredups
export HISTCONTROL=ignoreboth
export HISTIGNORE='pwd:ls:history:'
export HISTSIZE=4096
export EDITOR='/usr/bin/vim'
@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')
@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 / vmware-autostarts
Last active October 26, 2024 06:25
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