• Windows Server

    It’s not wget or curl, it’s iwr in Windows

    Powershell comes with a handy little cmdlet to download files from the internet called Invoke-WebRequest which is documented at https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-webrequest?view=powershell-7.2. There’s an alias for it so it can be called as just iwr. Let’s say there’s a file at https://pathtothefile/myfile.txt and we want to download it to the working directory as simply myfile.txt. That could be done with the following command: iwr -uri https://pathtothefile/myfile.txt -OutFile ./myfile.txt -UseBasicParsing -UseDefaultCredentials In the above example, we used the -uri to identify the target resource and -OutFile to list the local location. The above command used basic parsing as we were accessing a resource from an older server, although that wouldn’t be required for…

  • bash,  Mac OS X,  Mac Security

    Super-Simple Bash Graphs

    The sparkr gem is installed by default in macOS. To use it to produce simple graphs, simply run it followed by a series of integers: sparkr 12 110 250 110 12 The result would be as follows: This is useful for a quick and dirty visualization in scripts. For example, a series of 5, 10, 200 numbers that don’t have that much range where you’re just looking for a simple pattern. Like number of lines in logs, etc. Obviously, you can pay a lot of money for graphing frameworks and very fancy-schmancy tools. This is really just for me in small scripts.  Note: sparkr isn’t installed on all Mac systems.…

  • Apple Configurator,  Apps,  iPhone,  Mac OS X

    Get The Title Of An App From Apple App Store URLs

    When you’re building and manipulating apps in the Apple App Stores, it helps to be able to pull and parse pieces of data. Here, we’ll look at two strategies that you can use to do so. It’s worth noting that the purpose of this was to use the URL of an app from an MDM and then be able to script updating metadata about the app, given that vendors often change names of the display name of an app (e.g. Yelp is actually called “Yelp: Discover Local Favorites on the App Store”). First, we’ll grab a URL. This one is for Self Service: https://itunes.apple.com/us/app/self-service-mobile/id718509958?mt=8 If you don’t know the URL…

  • bash,  Mac OS X,  Mac OS X Server

    This New Years Day, Learn The Jot Command

    This New Years Day, Learn The Jot Command The jot command is one I haven’t used in awhile. But it’s still useful. Let’s take a look at a few of the things you can do with it. First, let’s just print lines into a new file called “century.txt” which we can do by running with the number of increments followed by the starting number, and then redirecting the output into the file name: jot 100 1 > ~/Desktop/century.txt Or to do integers instead, simply put the decimals: jot 100 1.00 > ~/Desktop/century.txt Or in descending order, jot – 100 1 > ~/Desktop/century.txt Now we could change the output to be…

  • Mac OS X Server

    Programatically Manage Jabber Chat Rooms In macOS Server

    Server comes with a command called RoomsAdminTool located at /Applications/Server.app/Contents/ServerRoot/usr/bin/RoomsAdminTool. This tool can list available rooms using a -l flag: RoomsAdminTool -l You can also create new rooms, using the following format, where krypted is the name of the room, the persistent option means the room is, er, persistent. The description option indicates a description used for the room. RoomsAdminTool -n krypted -c persistent yes description "This room is for friends of krypted only” To then delete the room, use the -d option: RoomsAdminTool -n krypted -d Add the -v to do it all verbosely. There are lots of other options as well, as follows (from the man page): Valid…

  • WordPress

    Using The WordPress API

    WordPress has an app. That means there’s an API to normalize communication using a predictable programmatic interface. In this case, as with many others, that’s done using a standard REST interface to communicate. The easiest way to interact with any API is to just read some stuff from the server via curl. You can feed curl the URL to the API by using your URL followed by /wp-json – as follows, assuming a URL of https://www.krypted.com: curl https://krypted.com//wp-json To view header information: curl -s -D - https://krypted.com/ -o /dev/null In the below example we’ll ask for a list of posts by adding /wp/v2/posts to the URL: curl https://krypted.com//wp-json/wp/v2/posts You’ll see…

  • Mac OS X,  Mac Security

    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…

  • Mac OS X Server,  Mac Security

    Decrease Time Delays When Scripting Safari

    When you’re regression testing, you frequently just don’t want any delays for scripts unless you intentionally sleep your scripts. By default Safari has an internal delay that I’d totally forgotten about. So if your GUI scripts (yes, I know, yuck) are taking too long to run, check this out and see if it helps: defaults write com.apple.Safari WebKitInitialTimedLayoutDelay 0 With a script I was recently working on, this made the thing take about an hour less. Might help for your stuffs, might not. If not, to undo: defaults delete com.apple.Safari WebKitInitialTimedLayoutDelay Enjoy.

  • 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…