This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Contains common functions that can be sourced by other bash scripts | |
function RunParallel | |
# Usage: Set the PROCESSES and CONCURRENCY variables and invoke RunParallel without parameters | |
# PROCESSES: An array of commands to execute | |
# CONCURRENCY: The number of commands to execute concurrently | |
# - Takes a list of processes in the PROCESSES variable, runs them in parallel, waits for | |
# each to complete, and then serializes their output (i.e. not interleaved). | |
# - If any process fails, then RunParallel will return a non-0 value. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import datetime as dt | |
import subprocess | |
class STD_DST(dt.tzinfo): | |
""" Determine if a datetime occured during STD or DST time """ | |
def dst(self, a): | |
# DST starts second Sunday in March at 2AM | |
d = dt.datetime(a.year, 3, 1, 2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
############################################################################### | |
# This script uploads a file to an AWS S3 bucket. It will optionally use KMS | |
# envelope encryption to encrypt a file on the client side before uploading | |
# to AWS S3. | |
# | |
# Envelope encryption fetches a data key from KMS and uses it to encrypt the | |
# file. The encrypted file is uploaded to an S3 bucket along with an encrypted | |
# version of the data key (it's encrypted with a KMS master key). You must | |
# have access to the KMS master key to decrypt the data key and file. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*options mprint mlogic symbolgen; | |
options errorabend fullstimer compress=binary; | |
options nofmterr validvarname=any; | |
/* | |
** SAS script to convert a data set to text-delimited format. The output file | |
** will be written to either the same directory where the SAS data set resides | |
** or to a user-specified file. | |
** | |
** sysparm must contain 5 :-separated values: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def execute_sql(self, sqlcmd, arg_list=()): | |
''' Returns the cursor if the SQL statement is successful, else | |
returns None if the SQL statement fails. | |
Automatically reconnects if the database connection is broken and | |
retries the SQL up to 5 times. | |
''' | |
logging.debug("Executing SQL: '%s', '%s'" % (sqlcmd, arg_list)) | |
for i in range(5): | |
try: | |
self.cursor.execute(sqlcmd, arg_list) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def connect(self): | |
''' Open a connection to the database ''' | |
logging.info("Connecting to database '%s'" % config['DB_DBNAME']) | |
dirname = os.path.dirname(os.path.realpath(sys.argv[0])) | |
DB_PASSWORD_FILE = (dirname + "/.dbpass." + config['DB_HOST'] + "." + | |
config['DB_USER']) | |
with open(DB_PASSWORD_FILE) as pwd: | |
DB_PASSWORD = pwd.readline().strip() | |
self.conn = psycopg2.connect("host='%s' port='%s' dbname='%s' " | |
"user='%s' password='%s'" % ( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/expect | |
set password [exec cat .pwd] | |
set timeout -1 | |
# Connect to host, enter password | |
spawn ssh -o ServerAliveInterval=5 -o ServerAliveCountMax=1 server-name.com | |
expect { | |
"Password: " {send "$password\r"; exp_continue} | |
"password: " {send "$password\r"; interact} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
############################################################################### | |
## mail_it.sh | |
## A bash script that sends email as either plain text or HTML. It allows | |
## multiple recipients, CC addresses, reply-to addresses, and attachments. | |
## | |
## Usage: mail_it.sh -s subject -m message -f from_address | |
## -t to_address[,...] [-c cc_address[,...]] [-r reply_to_address[,...]] | |
## [-a attachment[,...]] [-h] | |
## subject: email subject |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def perm_to_text(perm): | |
perms = { | |
"0": "---", | |
"1": "--x", | |
"2": "-w-", | |
"3": "-wx", | |
"4": "r--", | |
"5": "r-x", | |
"6": "rw-", | |
"7": "rwx" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
############################################################################### | |
# This script downloads an object from AWS S3. If the object was encrypted, | |
# it will be decrypted on the client side using KMS envelope encryption. | |
# | |
# Envelope encryption fetches a data key from KMS and uses it to encrypt the | |
# file. The encrypted file is uploaded to an S3 bucket along with an encrypted | |
# version of the data key (it's encrypted with a KMS master key). You must | |
# have access to the KMS master key to decrypt the data key and file. To | |
# decrypt, the file is downloaded to the client, the encrypted data key is |
NewerOlder