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 / 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 / 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 / add_localadmins_to_ssh
Last active February 15, 2022 00:53
This script will add local admin accounts to ssh_access group in Mac OS X. (10.7 or higher. May also work in 10.6)
#!/bin/bash
# set the input for lazy convenience
IFS=$' '
localadmins=$(/usr/bin/dscl localhost -read /Local/Default/Groups/admin GroupMembership | awk -F': ' '{print $2}')
for account in `echo $localadmins`; do
# add additional blocks like >> && ! [ "$account" == "username" ] << for additional exclusions
if ! [ "$account" == "root" ] && ! [ "$account" == "itstech" ]; then
@pmbuko
pmbuko / ad_pass_exp.sh
Last active August 13, 2021 17:15
This script contains all the logic I use to determine the number of days remaining until a user's Active Directory domain password expires. Helpful for troubleshooting where things are breaking down in ADPassMon. Make sure you have an active kerberos ticket before running or you will see 'ldap_sasl_interactive_bind_s' errors at the beginning of …
#!/bin/bash
myLDAP=$(scutil --dns | awk '/nameserver\[0\]/{print $3}' | 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
passExpires="no"
else
@pmbuko
pmbuko / installed_packages.sh
Created November 2, 2012 17:35
Scrape the OS X install logs for installed packages and return in nice sorted format
#!/bin/bash
for log in $(/bin/ls -r /var/log/install.log*); do
bzgrep 'Writing receipt' $log | awk '{print $1,$2,$3,$10}'
done
@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 / renewLionKerb.scpt
Created March 21, 2012 16:19
An AppleScript to interactively obtain/renew a kerberos ticket in Lion.
try
-- test for Kerberos ticket presence and attempt to renew
do shell script "/usr/bin/klist | /usr/bin/grep krbtgt"
do shell script "/usr/bin/kinit -R"
on error
-- offer to renew Kerberos ticket
set response to (display dialog "No Kerberos ticket was found. Do you want to renew it?" with icon 2 buttons {"No", "Yes"} default button "Yes")
if button returned of response is "Yes" then
try
set thePassword to text returned of (display dialog "Enter your password:" default answer "" with hidden answer)
@pmbuko
pmbuko / get_ordered_active_ens.py
Last active August 12, 2018 23:43
This python script returns a list of active ethernet interfaces in their service priority order. OS X only, as it depends on the 'networksetup' command.
#!/usr/bin/env python
from re import findall
from subprocess import check_output
def getOrderedInterfaces():
"""Returns all ethernet interfaces in service order."""
interfaces = check_output(['networksetup', '-listnetworkserviceorder'])
matches = findall(r' en[\d]+', interfaces)
return [ i.lstrip(' ') for i in matches ]
@pmbuko
pmbuko / finder-file-handler.applescript
Last active August 3, 2018 07:56
Use this code in an Applescript to create a file handler that will allow you to click on urls of the form "finder://~/Dropbox/Project/Documents" to open that location in the Finder.
on open location this_URL
-- passed paths should be "finder://[/path/to/directory]
-- spaces in path names should be replaced with a url-friendly '%20'
set x to the offset of ":" in this_URL
set passed_path to text from (x + 3) to -1 of this_URL
set my_path to do shell script "echo \"" & passed_path & "\" | awk '{gsub(\"%20\",\"\\\\ \"); print}'"
do shell script "open " & my_path
end open location
@pmbuko
pmbuko / syspref_handler.applescript
Created October 18, 2013 16:59
An applescript url handler that opens System Preference panes passed to it. (http://yourmacguy.wordpress.com/2013/07/17/make-your-own-url-handler/)
on open location this_URL
-- passed urls should be "syspref://[PaneName]
-- or "syspref://[Pane_Name]" -- no spaces
set x to the offset of ":" in this_URL
set sp to text from (x + 3) to -1 of this_URL
set pane to do shell script "echo \"" & sp & "\" | awk '{gsub(\"_\",\"\\\\ \"); print}'"
set h to path to home folder
set home to POSIX path of h
set path_heads to {"/System/", "/", home}
set pref_pane to text from (x + 3) to -1 of this_URL