The following command will remove all empty lines from a file called badcommand.sh: sed '/^$/d' badcommand.sh
-
-
Count Log Entries for a Pattern
You see a lot of entries for various things in log files. Here, we’re going to print out the number of entries with backupd in them: awk '/backupd/{print NR}' /var/log/system.log
-
Using odutil with opendirectoryd
The options for Open Directory continue to get more refined, aligning with opendirectoryd. The odutil command is becoming more and more useful with each version of OS X. Let’s inspect the directory service cache, using odutil with the show verb and the cache option: odutil show cache You can also view statistics for opendirectoryd using that show verb but with the statistics option: odutil show statistics And to see everything, use odutil with the show verb and the all option to get plenty of data to grep through: odutil show all The final show option we’ll look at is configuration. Here, you will also need to feed a directory nodename…
-
Edit NetBoot Sets Without Creating New Images
Mac admins spend a lot of time building images. In System Image Utility this can mean baking an image that just looks for a path of a NetRestore source and restores an operating system. Constantly making these is a pretty duplicative task. The goal of this article is to take a generic NetRestore NetBoot image and augment it in such a way that you don’t need to create new NetBoot images unless there’s a new build train. Instead, all you need to do is edit a file that changes the path (uri) of your image so that it can be restored. Using this, you can just stop the NetInstall service in…
-
Ask serveradmin If an Open Directory Certificate Authority is Available
The serveradmin command has an option to run commands. I’ve talked about these in past articles, for doing tasks like asking how many concurrent NFS connections are open on a host. Well, here’s another, and it’s a simple command. Here, we’re going to look at whether the Open Directory server has a CA. To do so, we’ll use the serveradmin command, along with the command verb. Then, we’ll add the certs option, followed by command= and then the payload of the command. In this case that’s isODCAPresent: sudo serveradmin command certs:command = isODCAPresent This is a simple, informational command, similar to the web:command of getSites or the mail:command of getConnectedUsers.…
-
Bypass the Application Downloaded From the Internet Warning in OS X
___ “is an application downloaded from the Internet. Are you sure you want to open it?” is a warning dialog that appears when you open an application that you downloaded from the Internet. When you install those software titles with automation, you can clear the attribute that causes the prompt, so you don’t get a lot of confusion from end users. TO do so, use the xattr command, using -d to delete the com.apple.quarantine attribute. Here, we’re going to do so recursively, using the -r option and finally defining the application: sudo xattr -d -r com.apple.quarantine /Applications/iExplorer.app
-
Unix Signals
When you run a kill command to stop a process from bash or the javax.realtime.POSIXSignalHandler class, you’re sending what’s known as a POSIX signal to the process. These signals can be called via their numeric representations or the signal (e.g. with the -s option of the kill command). Signals include the following: 1: SIGHUP – Close the controlling terminal when the controlling process dies 2: SIGINT – Send a keyboard interrupt 3: SIGQUIT – Quit from a keyboard/terminal 4: SIGILL – Terminate illegal instruction with a core dump and don’t restart 5: SIGTRAP – Send a trace/break trap (with core dump) 6: SIGABRT – Process an abort signal 7: SIGEMT…
-
Bash: A Silly wc Example
The wc command is used to count words, characters and lines. Here, we’ll run it a few different ways. -l shows the number of lines in a file. For example, in my home directory, I can use it to see how many lines are in my .gitconfig file: wc -l .gitconfig This would output something like the following: 11 .gitconfig Or count the number of characters with -c: wc -c .gitconfig Or check the number of words: wc -w .gitconfig You can also run it against multiple files. For example, here I’ll check the number of lines in both my .gitconfig file and my .gitignore_global files: wc -l .gitconfig .gitignore_global…
-
Restart Macs Down Immediately in OS X
You can shut (and restart) Macs down immediately using the shutdown command. To do so, run the following command: shutdown -r now
-
Use the textutil Command To Query Office Files For Metadata
You can use the textutil command to pull metadata information from Office documents. Here, we’ll use the -info option to do so: textutil -info hello.docx The output would be as follows: It might display: Type: Word format Size: 44068 bytes Length: 4234 characters Title: Author: Charles Edge Last Editor: Charles Edge Subject: Keywords: Created: 2015-06-28 08:21:00 -0900 Last Modified: 2015-06-28 10:02:00 -1200 Contents: Hello world