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

    Scripting Around Dropping Network Connections In OS X

    Dropping network connections can be incredibly frustrating. And finding the source can be a challenge. Over the years, I’ve found a number of troubleshooting methods, but the intermittent drop can be the worse to troubleshoot around. When this happens, I’ve occasionally resorted to scripting around failures, and dumping information into a log file to find the issue. For example, you may find that when a network connection fails, you have a very strong signal somewhere, or that you have a very weak signal on all networks. I’ve found there are three pretty simple commands to test joining/unjoining, and using networks (beyond the standard pings or port scans on hosts). The…

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

    Run a script directly from github

    There are a lot of scripts stored on github. And you can run them directly by curling them into bash. To do so, you’ll need a link to the raw script (using the github page with the URL of the script brings in all the cruft, so you’ll need to find the raw text). To grab that, click on the page with the script and then right-click  on Raw, as seen here: Then, throw out a bash command followed by < and then the URL you just copied into your clipboard in parenthesis: bash <(curl -Ls https://github.com/krypted/resetsoftwareupdate/raw/master/resetsoftwareupdate.sh)

  • Mac OS X,  Unix

    Quick Script Backups In OS X

    When I’m working on a little bash script, I’ll often make a backup, each time I save and test. Then I can revert back, if I need to. The syntax I’ll use is to cp and then curly-bracket the output into .bak files (that’s a 90s era file extension I use for such nonsense): cp filename.sh{,.bak} So if I’m writing a script called MYSCRIPT.sh: cp MYSCRIPT.sh{,.bak} The resultant backup of the script is MYSCRIPT.sh.bak.

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

    Bash: Check That A Script Is Running As Root

    Pretty much every script I’m working on these days must be run as root. Checking what user is running something is pretty straight forward, as there’s a built-in shell variable for $USER that contains the user running a script. To see this real quick, simply run the following: echo $USER You can then put this into your scripts. I’ve been using the same block of code for decades, which can be run in a script by itself if you’d like to paste this into one. if [[ $USER != "root" ]]; then echo "This script must be run as root" else echo "You are root" exit 1 fi Note: Keep in mind…

  • Mac OS X,  Mac OS X Server,  Mac Security,  Mass Deployment,  Ubuntu,  Unix

    Bash History Fun

    We tend to use a lot of commands in the Terminal app. That is, after all, what it’s there fore. And there’s a nice history of what we do. There are also a number of ways to view and manage the bash history. The simplest of which is the history command, which will show the previous commands run. Here, we’ll simply run it: history Keep in mind that this shows the history based on context, so if you sudo bash, you’ll potentially see a different history. You can also use the bash built-in fc command, which has the additional awesomeness of being able to edit and re-run commands from the…

  • Mac OS X,  Ubuntu,  Unix

    cd To The Previous Directory

    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.

  • Active Directory,  Mac OS X,  Mac OS X Server,  Mac Security,  Mass Deployment

    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…

  • Mac OS X,  Mac Security

    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…