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…
-
-
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…
-
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…
-
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,…
-
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…
-
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…
-
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"
-
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…
-
My Slides On MDM From MacAD.UK
As promised, here’s the slide deck from my talk at MacAD.UK in London. Enjoy! MacADUK_MDM_2017