View bash-snippets.sh
# conditional blocks based on presence of a process in a one-liner
ps -C docker >/dev/null && { echo Hey; echo docker\!;} || { echo What?; echo really?;}
# bash function to get yes/no feed back from the user (return is considered no here)
agree() {
local question="$1"
while true; do
read -p "$question " answer
case $answer in
View bgrep.sh
#!/bin/bash
usage() {
cat <<EOT
Usage: ${0##*/} [-l] [-h] pattern [arg2] ...
Prints lines containing a BRE pattern, after stripping binary data.
Sort of like strings command followed by grep, only better.
If no file paths are specified after the pattern, paths are
read from stdin (tip: feed with find).
Options:
View lingo-shell-xtra-snippets.ls
on listReadOnlyVolumes
return shell_cmd_list("mount | sed -n 's/^\/dev\/.* on \(\/.*\) (.*read-only.*/\1/p'")
end
on nonEmptyFolderExists atPosixPath
rslt = shell_cmd_list("ls " &qq(atPosixPath) &" 2>/dev/null")
return count(rslt) > 0
end
on directoryExists atPosixPath
View dir-vers.pl
#!/usr/bin/perl -w
use constant IFFTYPES => qw( RIFX XFIR );
use constant DIRTYPES => qw( MV93 39VM MC95 );
use constant {
INT_SIZE => 4,
VERSION_OFFSET => 40
};
use Getopt::Long;
#use diagnostics;
View genUID.sh
#!/bin/bash
# genUID.sh - A bash version of the genUID.app CLSID generator for Adobe Director MOA classes.
openssl rand -hex 16 | awk '{
printf "DEFINE_GUID(CLSID(CRegister), 0x%sL, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s);\n",
substr($0, 1, 8), substr($0, 9, 4), substr($0, 13, 4), substr($0, 17, 2),
substr($0, 19, 2), substr($0, 21, 2), substr($0, 23, 2), substr($0, 25, 2),
substr($0, 27, 2), substr($0, 29, 2), substr($0, 31, 2)
}' | \
View notifymail.sh
#/bin/bash
# usage:
# sudo nohup notifymail 2>&1 >/dev/null
# to see if it is already running
# ps ax | egrep ' (sh /Users/colet/bin/[n]otifymail)|([n]c -l 79)$'
[ $(whoami) != 'root' ] && echo must be root && exit
# first clean up any old related processes
View win2003-ntp.txt
net stop w32time
w32tm /unregister
w32tm /register
net time /setsntp:"tick.example.com,0x1 tock.example.com,0x1"
net start w32time
View smtp-test
telnet smtp.example.com 25
Trying 203.0.113.1...
Connected to smtp.example.com.
Escape character is '^]'.
220 example.com running My Bitchin Mail Server 1.0.0
HELO example.org
250 example.com hello example.org (198.51.100.1)
MAIL FROM:<postmaster@example.org>
250 2.1.5 sender OK
RCPT TO:<someone@example.com>
View mysql-notes
CREATE USER 'someuser'@'localhost' IDENTIFIED BY 'cleartext-password';
GRANT SELECT,INSERT,UPDATE,DELETE ON `database`.* TO 'someuser'@'localhost';
View stop-watch.sh
#!/bin/bash
START=$(date +%s)
read -s -n1 -p $'Press a key when done.\n'
ELAPSED_SECONDS=$(bc <<< "scale=10; ($(date +%s) - $START)")
if [ $ELAPSED_SECONDS -gt 60 ]; then
ELAPSED_MINUTES=$((ELAPSED_SECONDS / 60))
ELAPSED_SECONDS=$((ELAPSED_SECONDS - ELAPSED_MINUTES * 60))
echo -n "$ELAPSED_MINUTES minutes "
fi