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

    Using Inputs in Bash Scripts

    You can easily accept user provided input in bash by using the read command in bash for Linux and OS X. Here, we’ll echo out a choice to a user in a script, read the output into a variable called yn and then echo out the response: echo "Please enter y or n: " read yn echo "You chose wrong: $yn" Here, we used echo to simply write out what was chosen in the input. But we could also take this a little further and leverage a case statement to then run an action based on the choice selected: read -p "Should the file extension change warning be disabled (y/n)?…

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

    Grab Your WAN IP In Scripts

    Sometimes when I’m writing a script, I need something to phone home to something in the script. For example, this can tell another daemon where to ssh into when I invoke it remotely. So, let’s say I want to grab my WAN address in a script. I can use curl with a number of 3rd party sites (sites that often change. But, one that we can use here is ipecho.net. Here, we’ll look at their plain output page here: curl ipecho.net/plain This can then get output into a variable or file for processing in other parts of a script. For example, the output here is basically the same thing but…

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

    Caffeinate Your Commands

    The caffeinate command is pretty cool. It keeps your computer from going to sleep. It can run in a couple of different ways. There’s a timer that prevents sleep for a little while. You can also run another command from within caffeinate that keeps the system awake until the other command is finished. Here, we’ll scp a file called source file to a host called servername and keep the system from going to sleep until the process is finished: caffeinate -s scp sourcefile me:servername/targetfile Here, we’ll just use the boring command to tell the computer not to go to sleep for an hour: caffeinate -t 3600 &

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

    Disable File Extension Change Warning Dialog

    By default in OS X, when you change an extension for a file, you get a warning. This is somewhat annoying to me, as I do this pretty frequently and have never almost accidentally done so. So to disable, send a FXEnable ExtensionChangeWarning key into com.apple.finder as false: defaults write com.apple.finder FXEnableExtensionChangeWarning -bool false To then undo, simply run with a true key: defaults write com.apple.finder FXEnableExtensionChangeWarning -bool true

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

    Disable Unicast ARP Cache Validation In OS X

    As of OS X 10.9 (and in many cases more importantly in OS X Server for 10.9 and higher), OS X now performs ARP cache validation when trying to pass traffic over a router. If you are double NAT’d/use redundant gateways then the traffic can be interpreted as network redirection and cause some pretty bad packet loss/latency. You can disable this feature by turning off net.link.ether.net.arp_unicast_lim using sysctl: sysctl -w net.link.ether.inet.arp_unicast_lim=0 That will only disable unicast arp validation until the next reboot. If it fixes a latency problem you’re having then you can go ahead and make it permanent by adding the following line into /etc/sysctl.conf: net.link.ether.inet.arp_unicast_lim=0 If you’re still…

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

    Some minor updates to https://krypted.com/

    So a few months ago, closing in on 3,000 posts, the database got too big and krypted.com started suffering from innodb corruption, resulting in database outages. While I was able to get the site up, it was using a read-only database that kept me from doing any new articles or updates. It was a strange time in my life, like suddenly being single after living with someone since Y2K (when I started the site). But I got through it and was able to repair the relation… er, site. Now, with a new database that is free from corruption we’re ready to get to 6,000 posts! Also, I had a little…

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

    Command Line Firewall Management In OS X 10.10

    The tools to automate OS X firewall events from the command line are still stored in /usr/libexec/ApplicationFirewall. And you will still use socketfilterfw there for much of the heavy lifting. However, now there are much more helpful and functional options in socketfilterfw that will allow you to more easily script the firewall. Some tricks I’ve picked up with the Mac Firewall/alf scripting: Configure the firewall fully before turning it on (especially if you’re doing so through something like Casper, FileWave, Munki, or Absolute Manage where you might kick yourself out of your session otherwise). Whatever you do, you can always reset things back to defaults by removing the com.apple.alf.plist file…

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

    Don’t Use bless To Change Startup Disks Any More In OS X

    For a long time, we used the bless command to startup systems to a specific volume in OS X. Back in 2009 I started using the systemsetup command for more and more tasks. These days, I’m being guided to replace all of my bless options in scripts to systemsetup. The easy way to configure your startup volumes using systemsetup is to list the available volumes, set one as the startup volume and then check to see which one is the current volume. The first task is to list the available startup volumes, using the -liststartupdisks option: sudo systemsetup -liststartupdisks You can then set the disk as one that was listed…