Skip to content

Instantly share code, notes, and snippets.

View pmbuko's full-sized avatar
💁‍♂️
captive devopsian

Peter Bukowinski pmbuko

💁‍♂️
captive devopsian
View GitHub Profile
@pmbuko
pmbuko / quiet_mode_toggle.script
Last active February 18, 2022 00:49
Applescript to toggle a dark/quiet mode on your Mac.
tell application "System Events"
tell appearance preferences to set dark mode to not dark mode
keystroke "d" using {command down, option down, control down, shift down}
end tell
set curVolume to get volume settings
if output muted of curVolume is false then
set volume with output muted
else
set volume without output muted
@pmbuko
pmbuko / netbootch.sh
Created January 21, 2017 00:27
netbootch -- for archival purposes. ;)
#!/bin/bash
##############################################################
# #
# NETBOOTCH, by Peter Bukowinski (pmbuko@gmail.com) #
# last revised July 31, 2008 at 5:48pm #
# #
# ABOUT THIS SCRIPT: #
# This script makes it easy to change the default NetBoot #
# image hosted on an Xserve via the command line. It is an #
@pmbuko
pmbuko / gist:46443f1a4e077273b237d5e40953957e
Created June 8, 2016 17:09
Java's version command output looks multi-line but isn't.
❯ java -version
java version "1.8.0_51"
Java(TM) SE Runtime Environment (build 1.8.0_51-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.51-b03, mixed mode)
❯ java -version | head -1
java version "1.8.0_51"
Java(TM) SE Runtime Environment (build 1.8.0_51-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.51-b03, mixed mode)
@pmbuko
pmbuko / parallel_ssh.py
Last active March 1, 2020 07:03
parallel ssh commands. key-based auth *highly* recommended
#!/usr/bin/env python
#
# Pass any number of short hostnames to run cmd on all
# hosts in parallel and display the results nicely.
import sys
import subprocess
import multiprocessing
PROCESSES = 8
@pmbuko
pmbuko / rename_mac_to_primary_local_user.sh
Last active August 29, 2015 14:27
This script will change the hostname of a Mac to a dot-separated version of the full name of the most-commonly-logged-in user with a local home found under /Users.
#!/bin/bash
# This script will change the hostname of a Mac to a dot-separated version
# of the full name of the most-commonly-logged-in user with a local home.
# Give a list of usernames to ignore, separated by spaces
ignore_list=( root admin administrator bukowinskip )
# Get a list of usernames sorted by login frequency, limited to the last 100 logins
login_list=$(last -t console -100 | \
@pmbuko
pmbuko / chrome_plugin.py
Last active August 29, 2015 14:24
This program will disable or enable Chrome plugins by name for ALL local users on Mac OS X and must therefore be run as root. Chrome should not be running or the update may not take. The original Chrome prefs file is backed up with '.backup' appended to its name.
#!/usr/bin/env python
import sys, getopt, os, glob, shutil, json
# relative path to Chrome Default Prefs
chrome_prefs = "Library/Application Support/Google/Chrome/Default/Preferences"
def set_plugin_state(pref, plugin, state):
"""
This function parses the chrome prefs file passed to it, looking
@pmbuko
pmbuko / quick_ad_pass_exp.sh
Created July 10, 2015 20:43
This script will return info on Active Directory password expiration for the currently active user when run on a Mac bound to an AD domain.
#!/bin/bash
# This section uses python to get the current console user. You can
# usually just use the built-in $USER variable, but this is more
# robust.
USER=$(/usr/bin/python -c \
'from SystemConfiguration import SCDynamicStoreCopyConsoleUser;\
print SCDynamicStoreCopyConsoleUser(None, None, None)[0]')
# This looks up the password expiration date from AD. It's stored
@pmbuko
pmbuko / get_ad_pass_expiration.sh
Last active August 29, 2015 14:24
This script should return the date and time of a logged in OS X user's Active Directory password expiration. Please test and let me know if you get an accurate value.
#!/bin/bash
USER=$(/usr/bin/python -c \
'from SystemConfiguration import SCDynamicStoreCopyConsoleUser;\
print SCDynamicStoreCopyConsoleUser(None, None, None)[0]')
xWin=$(/usr/bin/dscl localhost read /Search/Users/$USER \
msDS-UserPasswordExpiryTimeComputed 2>/dev/null |\
/usr/bin/awk '/dsAttrTypeNative/{print $NF}')
xUnix=$(echo "($xWin/10000000)-11644473600" | bc)
/bin/date -r $xUnix
@pmbuko
pmbuko / ad_pass_exp.sh
Last active November 27, 2017 21:27
These are the shell commands that ADPassMon uses internally to get the information it needs.
#!/bin/bash
myDomain=$(dsconfigad -show | awk '/Active Directory Domain/{print $NF}')
myLDAP=$(dig -t srv _ldap._tcp.${myDomain} | awk '/^_ldap/{print $NF}' | head -1)
mySearchBase=$(ldapsearch -LLL -Q -s base -H ldap://${myLDAP} defaultNamingContext | awk '/defaultNamingContext/{print $2}')
uAC=$(dscl localhost read /Search/Users/$USER userAccountControl | awk '/:userAccountControl:/{print $2}')
if [[ $uAC =~ ^6 ]]; then
@pmbuko
pmbuko / change_password_pashua.py
Created December 22, 2014 18:32
A python example of a Pashua prompt window for changing passwords. It is just an example and doesn't actually change passwords.
#!/usr/bin/python
#
# Simple python example of a Pashua password prompt window for changing passwords.
# It prompts for the current password, new password, and new password verification.
# It does the verification and redisplays the prompt with feedback if the current or
# new passwords do not match.
#
# THIS WILL NOT ACTUALLY CHANGE PASSWORDS. I created this as an example of how you can
# design Pashua dialogs and work with their output.
#