Posts tagged bash
Bash shortcuts to run Rails commands through Spring, Bundler, or ye olde scripts
0Just about a year ago to date I posted some useful Bash shortcuts for Ruby on Rails commands. These are mix of aliases and functions that detect what version of Rails is present and routes commands which ever way that version expects, i.e. ./script/console
versus rails console
. Now that Rails 4.1 ships with Spring by default, there is yet one more way commands could be routed – through the spring binstubs. I’ve recently updated my shortcuts to account for this. Now my commands will use the binstubs if they are present, or fallback to the other version-dependent methods.
H/T to makandracards for helping me figure this out.
Some useful Bash shortcuts for Ruby on Rails commands
0Read an updated article on my Rails shortcuts: Bash shortcuts to run Rails commands through Spring, Bundler, or ye olde scripts
Like any developer, I spend a lot of time in the terminal typing out commands. Anything I can do to cut down on keystrokes is a daily win, which is why I’ve got over 50 bash alias
entries.
I frequently have to work on a several different Rails projects at a time, ranging in versions from 2.3 – 4.0. Hammering out commands for console
, server
or generate
can get pretty tedious by the end of the day, so I came up with a couple shortcuts that I’m particularly fond of:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | # RUBY / RUBY ON RAILS COMMANDS alias rails_mv="rails -v | sed 's/Rails \([0-9]\).*/\1/g'" alias bexec='bundle exec' alias brake='bundle exec rake' function cons () { if [ `rails_mv` -lt 3 ]; then ./script/console "$@" else bexec rails c "$@" fi } function gen () { if [ `rails_mv` -lt 3 ]; then ./script/generate "$@" else bexec rails g "$@" fi } function srv () { if [ `rails_mv` -lt 3 ]; then ./script/server "$@" else bexec rails s "$@" fi } alias sandbox='cons --sandbox' |
What I like most about the cons
, srv
and gen
commands is that they eliminate the mental overhead of context switching when going from the old 1.x and 2.x projects where each command is a separate bin file versus the newer 3.x+ project where they are just arguments to the rails
command – It’s the same alias for every project.
Using dig to view, backup and verify DNS zone records on OS X
0I was recently asked by a client to consolidate all of their DNS zone records and domain name registrations from 2 separate services to a single provider. The FAQ page of the current DNS service recommended using the named-xfer
shell command, but that utility isn’t available on OS X. I googled around and learned that dig
is a suitable alternative.
Finding the nameservers
Dig can be used to find nameserver information for a given domain:
1 2 3 4 | $ dig yourdomain.com NS +short ns1.nameserver.com. ns2.nameserver.com. ns3.nameserver.com. |
Viewing and Backing up DNS Records
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | $ dig @ns1.nameserver.com yourdomain.com IN ANY ;; Truncated, retrying in TCP mode. ; < <>> DiG 9.8.3-P1 < <>> @ns1.nameserver.com yourdomain.com IN ANY ; (1 server found) ;; global options: +cmd ;; Got answer: ;; ->>HEADER< <- opcode: QUERY, status: NOERROR, id: 12683 ;; flags: qr aa rd; QUERY: 1, ANSWER: 7, AUTHORITY: 0, ADDITIONAL: 5 ;; QUESTION SECTION: ;yourdomain.com. IN ANY ;; ANSWER SECTION: yourdomain.com. 14400 IN NS ns1.nameserver.com. yourdomain.com. 14400 IN NS ns2.nameserver.com. yourdomain.com. 14400 IN NS ns3.nameserver.com. yourdomain.com. 14400 IN MX 0 mx1.balanced.homie.mail.nameserver.com. yourdomain.com. 14400 IN MX 0 mx2.balanced.homie.mail.nameserver.com. yourdomain.com. 14400 IN A 69.163.240.35 yourdomain.com. 14400 IN SOA ns1.nameserver.com. hostmaster.nameserver.com. 2013122000 16668 1800 1814400 14400 ;; ADDITIONAL SECTION: ns1.nameserver.com. 14400 IN A 66.33.206.206 ns2.nameserver.com. 14400 IN A 208.96.10.221 ns3.nameserver.com. 14400 IN A 66.33.216.216 mx1.balanced.homie.mail.nameserver.com. 14400 IN A 208.97.132.209 mx2.balanced.homie.mail.nameserver.com. 14400 IN A 208.97.132.210 ;; Query time: 150 msec ;; SERVER: 66.33.206.206#53(66.33.206.206) ;; WHEN: Tue Feb 4 16:17:59 2014 ;; MSG SIZE rcvd: 305</code> |
Backing these up just requires you to send that output to a file: dig @ns1.nameserver.com yourdomain.com IN ANY >> dns-backup-yourdomain.com-ns1.nameserver.com
Once you’ve updated the nameservers for a domain you can verify if they’ve changed using the dig yourdomain.com NS +short
command.
Other useful dig
commands
1 2 | $ dig yourdomain.com A +short 69.163.240.35 |