Skip to content

Instantly share code, notes, and snippets.

@rockpapergoat
rockpapergoat / iterate_users.rb
Created November 26, 2010 23:56
trying to find ways to grab account details via dscl on os x clients
#!/usr/bin/env ruby -wKU
# dump userlist using dscl and find accounts above UID 500
def iterate_users
userlist=`/usr/bin/dscl . -list /users UniqueID`.split("\n").slice(1..-1)
newlist = userlist.map { |pair| pair.split(" ").to_a }
over500 = newlist.find_all { |item| item.at(1).to_i > 500 }
p over500
end
iterate_users
@rockpapergoat
rockpapergoat / iterate_users2.rb
Created November 27, 2010 00:07
another try, declaring only one variable instead of three
#!/usr/bin/env ruby -wKU
def iterate_users
userlist=`/usr/bin/dscl . -list /users UniqueID`.split("\n").map { |pair| pair.split(" ").to_a }.find_all { |item| item.at(1).to_i > 500 }
p userlist
end
iterate_users
#!/usr/bin/env ruby -wKU
# 101221, nate
# attempt to fix perm/ownership issues on locally attached storage
# for some reason, these arrays were configured with ownership disabled
#
require 'osx/cocoa'
# get name of root volume,
# subtract it from array of total volumes
@rockpapergoat
rockpapergoat / openuri_selfsolve.rb
Created February 8, 2011 18:50
get mac applecare coverage details
#!/usr/bin/env ruby
# get a machine's applecare warranty expiration
# 100605, nate, initial version
# 100605, updated with collaboration from glarizza
# cf. http://pastie.org/993496
# cf. http://pastie.org/994884, with facter attribute additions
# 101222, require rubygems, facter; used facter to get serial (not as portable)
# 101222, reverted to system_profiler, as it requires fewer dependencies
# 110208, new url worked out by gary
# 110208, openssl workaround, cf. http://snippets.aktagon.com/snippets/370-Hack-for-using-OpenURI-with-SSL
@rockpapergoat
rockpapergoat / get_app_version.rb
Created February 24, 2011 14:52
accepts an array as arguments on the command line or will loop through /Applications
#!/usr/bin/env ruby -wKU
# 110224, revised with loop to accept an array
def get_version(apps)
apps.each do |app|
if File.exists?("#{app}/Contents/Info.plist")
vers = `/usr/bin/defaults read "#{app}"/Contents/Info CFBundleShortVersionString`.chomp
puts "#{app.sub(/\/Applications\//, '')}: #{vers}"
$?.success? ? vers : "ERROR: could not get version"
@rockpapergoat
rockpapergoat / get_nonsys_users.rb
Created March 5, 2011 17:52
capture users and uids, filtering for > 500 uids
#!/usr/bin/env ruby -wKU
# capture users and uids, filtering for > 500 uids
# want to emulate dscl . -list /users UniqueID | awk '$2 > 500 { print $1 }'
def get_nonsys_users
users = `dscl . -list /users UniqueID`.split("\n").collect! {|u| u.sub!(/\ +/, ",").split(",").to_a}.select {|u| u[1].to_i > 500}
end
p get_nonsys_users
@rockpapergoat
rockpapergoat / get_nonsys_users1.rb
Created March 5, 2011 18:23
just filter users, not uids
#!/usr/bin/env ruby -wKU
def non_sys_users
users = `dscl . -list /users`.split("\n").reject { |user| user.match(/^_/) or ["n8","root","puppet","daemon", "Guest", "nobody"].include?(user) }
end
p non_sys_users
@rockpapergoat
rockpapergoat / get_users_etc.rb
Created March 5, 2011 20:37
more user record stuff
#!/usr/bin/env ruby -wKU
# cf. http://twitter.com/nigelkersten/status/44114754112995328
require 'pp'
require 'etc'
users = []
Etc.passwd() { |u|
users << Hash[u.name, u.uid] if u.uid >= 500
}
pp users
@rockpapergoat
rockpapergoat / java exceptions starting casper
Created April 19, 2011 14:40
starting tomcat5 with server.xml configured to run jamf's casper web app
errors on start:
Starting tomcat5: [ OK ]
at org.apache.catalina.startup.Catalina.await(Catalina.java:616)
at org.apache.catalina.startup.Catalina.start(Catalina.java:576)
... 6 more
Using CATALINA_BASE: /usr/share/tomcat5
Using CATALINA_HOME: /usr/share/tomcat5
Using CATALINA_TMPDIR: /usr/share/tomcat5/temp
Using JRE_HOME:
# 110506
# reposado clone manifest
# pythonversion comes from a custom fact which should be instaled via factsync
case $pythonversion {
/2.6/: {
# will this test actually succeed?
include reposado_install
}
default: {