• Mac OS X,  Mac OS X Server

    Use awk to evaluate compound conditions

    You search for items in macOS using compound conditions in a number of ways. One way is with awk. Here, we’re going to grab the output of a simple ls command. That gets piped into an awk statement. Then we’re going to look at the expression to evaluate. Basically, we’re going to say anything that contains com. as well as apple and .plist. Because it’s ls, we’re looking for names of files that match those patterns. Each pattern is listed in brackets. And then there’s the {print} to lay out the action of printing to the files that match the pattern to the screen: ls |awk '/[com.][apple][.plist]/ {print}' Note: I…

  • Mac OS X

    macOS Logging Subsystems In A Gist

    If you happen to be tweaking the macOS subsystems for logging, I’ve put them into a little python class. If you need it, find it at this gist: https://gist.github.com/krypted/495e48a995b2c08d25dc4f67358d1983 Could use an array of all the levels, TTLs, and options. But I’ll get to that when I get some time. If this is all you need, though: class Logging(object): __name__ = 'logger.info(1)' plist = '/System/Library/Preferences/Logging/Subsystems/' def __init__(__name__, plist, *args, **kwargs): super(getLogger/, self).__init__() logger.info('Input parameters:\n' 'accessibility: "{com.apple.Accessibility.plist}"\n' 'StandaloneHIDFudPlugins: "{com.apple.StandaloneHIDFudPlugins.plist}"\n' 'duetactivityscheduler: "{com.apple.duetactivityscheduler.plist}"\n' 'passkit: "{com.apple.passkit.plist}"\n' 'AppKit: "{com.apple.AppKit.plist}"\n' 'SystemConfiguration: "{com.apple.SystemConfiguration.plist}"\n' 'eapol: "{com.apple.eapol.plist}"\n' 'persona: "{com.apple.persona.plist}"\n' 'AppleIR: "{com.apple.AppleIR.plist}"\n' 'TCC: "{com.apple.TCC.plist}"\n' 'icloudpreferences: "{com.apple.icloudpreferences.plist}"\n' 'apple.pf: "{com.apple.pf.plist}"\n' 'AssetCache: "{com.apple.AssetCache.plist}"\n' 'TimeMachine: "{com.apple.TimeMachine.plist}"\n' 'internetAccounts: "{com.apple.internetAccounts.plist}"\n' 'photoanalysisd.graph: "{com.apple.photoanalysisd.graph.plist}"\n' 'AssetCacheServices: "{com.apple.AssetCacheServices.plist}"\n' 'Transport: "{com.apple.Transport.plist}"\n'…

  • bash,  Mac OS X,  Mac OS X Server,  Mac Security,  Ubuntu

    Programmatically Grab Active DNS Servers On macOS

    One of my favorite things about grabbing things with scripts is just how many ways (and sometimes how needfully or needlessly convoluted you can make them) to grab the same pieces of information. For example, something as simple as what hosts you use to resolve names on a Mac. There are a number of ways to grab what DNS server a device is using in macOS. So when you’re running a script you might choose to grab DNS information one way or another, according to what you’re after. Some of this might seem more complicated than it should be. And that’s correct… resolv.conf The /etc/resolv.conf file is updated automatically to…

  • Mac OS X,  Mac OS X Server,  Mac Security,  Unix

    Basic Bash Functions

    According to @johnkitzmiller, you can’t spell function without fun. So let’s have some fun! What’s a function? Think of it as a script inside a script. Define functions at the beginning of the script instead of making repeated calls to the same task within a script. The other nice thing about functions is that the act of compartmentalization makes them simple to insert into a number of different scripts. For example, if you do a lot of curl commands to pull down something in a lot of different scripts, having the grabbing of the data as a function, then the parsing of it into an array as a function and…

  • Mac OS X,  SQL

    Mapping New SQLite Databases

    I’ve written about SQLite databases here and there over the years. A number of Apple tools and third party tools for the platform run on SQLite and it’s usually a pretty straight forward process to get into a database and inspect what’s there and how you might programmatically interact with tools that store data in SQLite. And I’ll frequently use a tool like Navicat to quickly and visually hop in and look at what happens when I edit data that then gets committed to the database. But I don’t always have tools like that around. So when I want to inspect new databases, or at least those new to me,…

  • Mac OS X,  Mac Security

    Cookie Management With Curl

    To tell curl that you can read and write cookies, first we’ll start the engine using an empty cookie jar, using the -b option, which always reads cookies into memory: curl -b newcookiejar https://krypted.com If your site can set cookies you can then read them with the -L option curl -L -b newcookiejar https://krypted.com The response should be similar to the following: Reading cookies from file Curl also supports reading cookies in from the Netscape cookie format, used by defining a cookies.txt file instead: curl -L -b cookies.txt https://krypted.com If the server updates the cookies in a response, curl would update that cookie in memory but unless you write something…

  • Mac OS X,  Mac OS X Server,  Mac Security,  Network Infrastructure

    Backup Filewave Databases

    You can quickly and easily back up your Filewave databases using the fwcontrol command to stop a Filewave server (thus preserving the integrity of the data you are backing up) and then backing up the database using the /fwxserver directory. To get started, we’ll first down the server. This is done using the fwcontrol command along with the server option and the stop verb, as follows: sudo fwcontrol server stop Now that there won’t be data trying to commit into the database, let’s make a backup of the database directory using the cp command: cp -rp /fwxserver/DB ~/Desktop/Databasebak To start the database, use the decontrol command with the server option…

  • Mac OS X,  Unix

    View The Content Of Files Without Comments In Bash

    So I comment a lot of lines out in my /etc/hosts file. This usually means that I end up with a lot of cruft at the top of my file. And while I write comments into files and scripts here and there, I don’t always want to see them. So I can grep them out by piping the output of the file to grep as follows: cat /etc/hosts | grep -v "^#" You could also do the same, eliminating all lines that start with a “v” instead: cat !$ | grep -v "^v"

  • Mac OS X,  Mac OS X Server,  Mass Deployment

    APNs Logs on macOS

    I originally wrote this back in 2015 as an article for troubleshooting APNs traffic on a Profile Manager server. But it turns out that troubleshooting push notification communications between macOS Server and Apple’s Push Notification is basically the same as troubleshooting the apsd client on macOS. Basically, we’re gonna’ put the APNs daemon, apsd, into debug mode. To enable APNS debug logging, run these commands: defaults write /Library/Preferences/com.apple.apsd APSLogLevel -int 7 defaults write /Library/Preferences/com.apple.apsd APSWriteLogs -bool TRUE killall apsd Then use tail -f to watch the apsd.log file at /Library/Logs/apsd.log. Be wary, as this can fill up your system. So to disable, use these commands: defaults write /Library/Preferences/com.apple.apsd APSWriteLogs -bool FALSE defaults delete…