When running a DNS/BIND server on Linux or macOS, you can check the version number by running a simple named command with the -v option. named -v The output is as follows: BIND 9.9.7-P3 (Extended Support Version)
-
-
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)
-
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.
-
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…
-
An Introduction To The Mac Command Line
-
Make Changes to the Chromium rootfs
By default, the Chromium OS rootfs is read-only. If you boot the system in developer mode, you will be able to disable rootfs verification and modify existing files or write new files into the file system. Before you do this, note that your file system will no longer be verifiable (won’t checksum properly) and you’ll end up needing to restore a recovery image in order to get back to normal mode. So this might be a bit dangerous if you’re not using the device for something like regression analysis (why I needed to do this). To make the file system writeable, first fire up a command prompt via crosh, by using Control-Alt-T…
-
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…
-
Removing Those Thousands Of Empty Directories In Bash
Earlier, we looked at creating thousands of empty directories. Today, we’re going to get rid of them. But we need to get rid of only empty directories. To do so, we’ll use the find command: find . -depth -type d -empty -exec rmdir {} \; Now, we can put both into a script: mkdir $(printf '%05d\n' {1..10000}) find . -depth -type d -empty -exec rmdir {} \;
-
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)?…
-
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…