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 / changeip
Created February 23, 2012 19:31
Script to change rhel/fedora ip address, meant to be used in single-user mode.
#!/bin/bash
if [[ $# != 1 ]]; then echo "You must supply a single IP address." && exit 1; fi
newip="$1"
config="/etc/sysconfig/network-scripts/ifcfg-eth0"
oldip=$(awk -F= '/IPADDR/{gsub("\"","");print $2}' $config)
newgw=$(echo $newip | awk '{sub(".[0-9]+$",".1"); print}')
echo ""
@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 / 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 / smb_mount.scpt
Created December 5, 2012 03:13
smb mount script example
try
set uname to do shell script "/usr/bin/whoami"
set passwd to text returned of (display dialog "Please enter your password:" default answer "" with hidden answer)
mount volume "smb://" & uname & ":" & passwd & "@server/share"
on error theError
display dialog theError buttons "Darn" default button 1 with icon 2
end try
@pmbuko
pmbuko / removeThe2.sh
Last active December 16, 2015 03:49
This script will, in the specified directory, find files ending with a space and a 2 -- ' 2' -- and strip that ending off matching files. Read inline comments for more info.
#!/bin/bash
# Explicitly set the directory you want to operate on here
workingPath="/your/path/here"
# Set a custom internal field separator to ease handling
# of filenames that contain spaces
IFS=$'\n'
# Identify files that end in ' 2' and tack on our custom
@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 / ipmi_from_eth0
Created May 1, 2013 19:07
This script sets up a RHEL(-like) host's ipmi interface with a static address based on eth0's ip address. It uses 'cut' because our eth0 ip addresses are all the same length. It requires ipmitool to be installed. We get it via the 'OpenIPMI' package.
#!/bin/bash
eth0addr=$(/sbin/ip addr show eth0 | /bin/awk '/inet/{gsub("/.+","");print $2}')
ipone=$(/bin/echo $eth0addr | /bin/cut -c1-9)
iptwo=$(/bin/echo $eth0addr | /bin/cut -c11-12)
ipnet=$(/bin/echo $eth0addr | /bin/cut -c1-5)
/usr/bin/ipmitool lan set 1 ipsrc static && \
/usr/bin/ipmitool lan set 1 ipaddr ${ipone}.2${iptwo} && \
/usr/bin/ipmitool lan set 1 defgw ipaddr ${ipnet}.0.1 && \
/usr/bin/ipmitool lan set 1 netmask 255.255.0.0 && \
@pmbuko
pmbuko / mkclusterscratch.sh
Last active December 18, 2015 19:29
This was too ridiculous not to share. (I wrote it before I learned python.) This script outputs a puppet manifest file that is used to manage local scratch directories for each compute cluster user on all our computer cluster nodes. I realize it is an abomination and welcome slaps to the face and derision as long as they're done lovingly.
#!/bin/bash
##########################################
# MKCLUSTERSCRATCH -last modified 10/10/14
##########################################
function help {
cat <<EOF
MKCLUSTERSCRATCH TOOL
@pmbuko
pmbuko / getsid
Created July 16, 2013 14:22
Add to your .bashrc. Works on an AD-bound mac with directory search path set up properly. 'getsid [username]' will return the user's SID.
getsid () { dscl localhost -read /Search/Users/$1 SMBSID 2>/dev/null | awk '{print $2}'; }
@pmbuko
pmbuko / growl_register
Last active December 21, 2015 21:39
test growl applescript to debug adpassmon
tell application "System Events"
set isRunning to (count of (every process whose bundle identifier is "com.Growl.GrowlHelperApp")) > 0
end tell
if isRunning then
tell application id "com.Growl.GrowlHelperApp"
-- Make a list of all notification types that this script will ever send:
set the allNotificationsList to {"Test Notification"}
-- Make a list of the enabled notifications. Others can be enabled in Growl prefs.