Tiny Deathstars of Foulness

The cd command has lots of fun little shortcuts. One I use frequently is the -. The ~ always takes you to your home directory, but using cd – will take you to the last directory you were in. For example, if you do the following on a Mac: cd ~ Then you do .. (which is a shortcut for the directory above the one you’re in): cd .. Then pwd will show that you’re in /Users. But, if you cd to – again: cd - Now you’re back in your home folder. The – expands to OLDPWD. Quick tip. Nothing more to see here.

July 20th, 2015

Posted In: Mac OS X, Ubuntu, Unix

Tags: , , , , ,

The following command will remove all empty lines from a file called sed '/^$/d'

July 12th, 2015

Posted In: Mac OS X, Mac OS X Server, Ubuntu

Tags: , , , ,

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 into the command: odutil show configuration /Search Now, /Search is a node but there are a lot. You can use show with nodes to see a listing of all the nodes: odutil show nodes You can then see which pids have references to opendirectoryd as well as the nodenames, reference IDs, and session IDs. All of this can be very helpful when troubleshooting Open Directory issues. One thing I find I do pretty frequently is resetting statistics then repeating a process that is causing a problem so I can view only the updated statistics. To do so: odutil reset statistics You can also disable statistics (I’ve seen them create performance concerns: odutil set statistics off Or to turn them back on: odutil set statistics on Once upon a time you could killall DirectoryService with a -usr level to set various logging levels. With opendirectoryd, we can still do that, but it’s less cludgy with odutil. Here, we’ll set the logging level as detailed as we can get: odutil set log debug Other levels, in ascending order of verbosity, include alert, critical, error, warning, notice, and info.

July 10th, 2015

Posted In: Active Directory, Mac OS X, Mac OS X Server, Mac Security, Mass Deployment

Tags: , , , , , , ,

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 – Send the signal when emulator traps happen
  • 8:SIGFPE – Terminate floating point errors (erroneous arithmetic operations) with a core dump
  • 9: SIGKILL – Kill a signal outright (kill cannot be ignored)
  • 10: SIGBUS – Terminate access (some portion of a memory object) with a core dump
  • 11: SIGSEGV – Terminate with a core dump – Invalid memory reference
  • 12: SIGSYS – Bad system call
  • 13: SIGPIPE – Terminate and write on the pipe
  • 14: SIGALRM – Timed kill of a signal
  • 15: SIGTERM – Software termination of a signal
  • 16: SIGUSR1 – User defined signal 1, with SIGUSR2 as user defined signal 2
  • 17: SIGTERM – Software termination of a signal
  • 18: SIGCHLD – Child status change
  • 19: SIGPWR – Send the signal when the system encounters a power failure
  • 20: SIGWINCH – Send the signal to a process when the window changes
  • 21: SIGURG – Ignore signal, high bandwidth data
  • 22: SIGIO – Terminate pollable event
  • 23: SIGSTOP – Stop executing (cannot be ignored or caught by an exception)
  • 24: SIGTSTP – Terminate a stop signal.
  • 25: SIGCONT – If stopped, continue executing a process
  • 26: SIGTTIN – Background process is attempting to read
  • 27: SIGTTOU – Background process is attempting to write
  • 28: SIGVTALTM – Expired virtual timer
  • 29: SIGPROF – Terminate Profiling timer
  • 30: SIGXCPU – Past the CPU time limit, terminate with a core dump
  • 31: SIGXFSZ – Past the file size limit, terminate with a core dump
  • 32: SIGWAITING – Suspend execution of the process until a defined signal is sent
  • 33: SIGLWP – Send when the implementing threading requires a signal
  • 34: SIGFREEZE – Deprecated
  • 35: SIGTHAW – Deprecated
  • 36: SIGCANCEL – Deprecated
  • 37: SIGLOST – Send the signal when encountering a lost file lock
To put these in practice, let’s use the kill command from bash, with the -s option followed by SIGTERM and then the pid number: sudo kill -s SIGTERM 20341

July 5th, 2015

Posted In: Mac OS X, Mac Security

Tags: , , , , , ,

In bash, you can run multiple commands in a single line of a script. You do so by separating them with a semi-colon (;). The great thing about this is that if you end up using a variable, you can pass it on to subsequent commands. Here, we’re going to string three commands together and then echo the output: a=1;b=2;c=$a+$b;echo $c because we told c to be $a + $b, the $a expands to 1 and the $b expands to 2, we throw them together and then echo out the contents of c$ which appears as follows: 1+2 Now, we could have this thing do math as well, by wrapping the mathematical operation in double-parenthesis, which bash treats as an arithmetic expansion: a=1;b=2;c=(($a+$b));echo $c The output this one is simply 3.

June 15th, 2015

Posted In: Mac OS X, Mac OS X Server, Ubuntu, Unix

Tags: , , , , , , , , ,

Popped in a list of Linux bash commands here:

January 24th, 2015

Posted In: Ubuntu

Tags: , , , , ,

Merry Christmas ya’ll!
On the first day of Christmas my true love gave to me one 32 gig iPad On the second day of Christmas my true love gave to me two bash one-liners On the third day of Christmas my true love gave to me three Red Hat servers On the fourth day of Christmas my true love gave to me four email blasts On the fifth day of Christmas my true love gave to me five retweets On the sixth day of Christmas my true love gave to me six regular expressions On the seventh day of Christmas my true love gave to me seven lines of perl On the eighth day of Christmas my true love gave to me eight app store apps On the ninth day of Christmas my true love gave to me nine AWS instances On the tenth day of Christmas my true love gave to me ten Active Directory forests On the eleventh day of Christmas my true love gave to me 11 crappy python scripts On the twelfth day of Christmas my true love gave to me 12 craft brews

December 25th, 2014

Posted In: iPhone, Mac OS X, Mac OS X Server, Mac Security, Mass Deployment

Tags: , , , , , , , , , , , , , ,

I was recently building some preflight scripts and was looking to record some information about a machine live, before proceeding with a script. I found the cheapest way to determine information about architectures and chipsets when scripting preflight scripts for OS X to be the arch and machine commands respectively. For example, to verify the architecture is i386, use the arch command with no options: /usr/bin/arch Which simply outputs “i386”: i386 To check the machine type, simply use the machine command: /usr/bin/machine Which outputs as follows: x86_64h

December 14th, 2014

Posted In: Mac OS X, Mac OS X Server, Mac Security, Mass Deployment, Network Infrastructure

Tags: , , , , , , ,

Recently I was working on a project where we were isolating IP addresses by country. In the process, I found an easy little tool built right into OS X called ip2cc. Using ip2cc, you can lookup what country an IP is in. To do so, simply run ip2cc followed by a name or ip address. For example, to lookup you might run: ip2cc Or to lookup Much Music, you might run: ip2cc The output would be: IP::Country modules (v2.28) Copyright (c) 2002-13 Nigel Wetters Gourlay Database updated Wed May 15 15:29:48 2013 Name: Address: Country: CA (Canada) You can just get the country line: ip2cc | grep Country: To just get the country code: ip2cc | grep Country: | awk '{ print $2 }' Finally, ip2cc is located at /usr/bin/ip2cc so we’ll complicate things just a tad by replacing the hostname with the current IP (note that private IPs can’t be looked up, so this would only work if you’re rocking on a wan ip or feeding it what a curl from a service like whatismyip brings back): ip2cc `ipconfig getifaddr en0` | grep Country: | awk '{ print $2 }'

December 13th, 2014

Posted In: Mac OS X, Mac OS X Server

Tags: , , , , , , , , , ,

When running commands that are going to take awhile, I frequently start them with the nohup command, disown the command from the current session or queue them for later execution. The reason is that if I’m running them from a Terminal or SSH session and the session is broken I want to make sure they complete. To schedule a job for later execution, use at. For example, if I want to perform a simple command, I can schedule it in a minute by running it as an echo piped to at: echo "" | at now + 2 minutes Note, if using 1 minute, you’ll need that to be singular. But you can also disown the job. To do so, end a command with an & symbol. So, running a command or script that will take awhile with an ampersand at the end displays the job number for the command and then you can disown it by running disown followed by -h at the end. for example: du -d 0 & disown -h If you choose not to disown the job, you can check running jobs using the jobs command at any time: jobs Nohup runs a command or script in the background even after a shell has been stopped: nohup cvfsck -nv goldengirls & The above command runs the command between nohup and the & symbol in the background. By default, you’ll then have the output to the command run in the nohup.out file in your home directory. So if your username were krypted, you could tail the output using the following command: tail -f /Users/krypted/nohup.out You can also use screen and then reconnect to that screen. For example, use screen with a -t to create a new screen: screen -t sanconfigchange Then run a command: xsanctl sanConfigChanged Then later, reconnect to your screen: screen -x And you can control-n or control-a to scroll through running background processes this way, provided each is in its own screen. Finally, in AIX you can actually use the bg command. I used to really like this as I could basically move an existing job into the background if I’d already invoked it from a screen/session. For example, you have pid 88909 running and you want to put it into the background. You can just run bg 88909 and throw it into the background, allowing you to close a tty. But then if you’d like to look at it later, you can always pop it back using, you guessed it, fg. This only worked in AIX really, but is a great process management tool.

January 6th, 2014

Posted In: Mac OS X, Mac OS X Server, Mac Security, Mass Deployment, Ubuntu, Unix, VMware, Xsan

Tags: , , , , , , , , ,

« Previous PageNext Page »