bash

Human readable, sorted file sizes

A handy alias I use in my .bashrc when I'm trying to find large files/directories:

alias human_du_sort='FILES=$(du -sh *); echo "${FILES}" | grep "[0-9]G" | sort -nr;echo "${FILES}" |grep "[0-9]M" | sort -nr;'
Tags:

Script to download the latest Chromium build

An extremely simple script to download and install the latest build of chromium for mac:

Stick that in your crontab, and you're good to go!

Tags:

Drupal multisite database backup

I'm currently in the middle of moving all my sites over to a new VPS, so I needed to quickly dump all the databases to migrate them. I had a script that handled drupal db dumps pretty well, but it didn't do multisite, so I threw this together:

  • Copy that into something like "multisite_db_backup.sh"
  • Change the "MYSQLDUMP_DIR" variable to wherever you want the sql dumps stored
  • Move it somewhere within your PATH (I use ~/bin/)
  • Make it executable (chmod +x multisite_db_backup.sh)
  • Run it in the root directory of your drupal install (cd drupal6; ./multisite_db_backup.sh"

Tested on debian and Mac OS 10.5.

Automating update.php

I've been playing around with scripting update.php for a while now. I remember having a working script a few months back, but I never really put it into production and it looks like there's been some Drupal core changes that broke what I wrote before anyhow. I've rewritten most of it, and from what I can tell, it works pretty well for Drupal 6.

One of the main goals of any Drupal shell script that I write, is that it works on any Drupal installation, without bootstrapping. This is essential for me at work since we run a lot of individual Drupal installs. I'm transitioning over to drush to replace some of my scripts, but drush gets information about the site by bootstrapping. This makes a lot of sense for what it does, but it takes a bit more setting up, and isn't as portable as a vanilla bash script.

So with that in mind, here are a couple things to note about this script (and any other Drupal-relation shell script I post):

Adding list items via the Backpack API

While my co-worker and I were discussing how nice it would be to have a document online that we could both work on simultaneously to track each other's progress, I suggested Backpack. I'd used it once before with someone else who used it regularly, but never really came back to it because I could never justify paying monthly for a service like that. I found that they had a free version, so I went ahead and created a site for us. We had a pretty long list that we wanted to turn into to-do items, and it looked like the only way to get them in was to type them all out by hand. I appreciate how easy they made it to type out to-do items, but if you've already got the list, there's no sense in typing it all out. After a quick look at the Backpack API, I threw this together, which worked as expected: [code lang="bash"]sh backpack.sh < list[/code] [code lang="bash"] #!/bin/bash LIST=`cat $1` for i in ${LIST} do curl -H "Content-Type: application/xml" -d "YourAPITokenGoesHere$i" http://yoursite.backpackit.com/ws/page//lists//items/add done [/code] The "list" file is just a text file with each item on a new line.
Syndicate content