Automating WordPress updates with cron and the wp-cli

Ain’t nobody got time to worry about updates. I’d rather have it break while updating than have it hacked by a script kiddie because I’ve neglected to login for a while. We will see if this ever breaks anything.

Install WordPress-CLI if you have not already.

Add all your sites to the script:

declare -a arr=(

for i in "${arr[@]}"
  echo $i
  cd /usr/share/nginx/html/$i
  sudo -u nobody wp core update

NOTE: Substitute /usr/share/nginx/html for the directory that holds your WordPress sites. Change user nobody to the user that owns the aforementioned directories. Check with ls -al, it might be the user that apache/nginx runs as, check that with top, htop, or ps -aux

Make sure it’s executable:

chmod +x

Run the script daily and live dangerously!

30 2 * * * bash /home/anthony/ >/dev/null 2>&1

Linux schedule a one off reboot or task

So the server requires a reboot because you updated the kernel but clients are using it and you don’t work at 1:00am? Not a problem…

echo "/sbin/shutdown -r now" |at 01:00 tomorrow

You can also the check the queued jobs with:


job 15 at Wed May  6 04:00:00 2015

And you can cancel the job like so:

at -r jobid

Or you can delete all jobs with:

atrm $(atq | cut -f1)

And as always RTFM

USDA Nutrient Data SR23 POSTGRES SQL dump

I found the mysql dump online but these days I prefer Postgres. For others who are in the same boat as me, I thought I would save you the troubles! Enjoy.

USDA Nutrient Data (SR23) Postgres Dump

I used py-mysql2pgsql and renamed all the tables to lower case.

I plan to hook this data into elastic search so that I can search on it with a rails api and return JSON. Maybe I’ll open source the elastic search rails API I’m going to build.


I noticed that this data set is missing the food categories, you can seed these with this:

# db/seeds.rb

groups = [
  ["0100", "Dairy and Egg Products"],
  ["0200", "Spices and Herbs"],
  ["0300", "Baby Foods"],
  ["0400", "Fats and Oils"],
  ["0500", "Poultry Products"],
  ["0600", "Soups, Sauces, and Gravies"],
  ["0700", "Sausages and Luncheon Meats"],
  ["0800", "Breakfast Cereals"],
  ["0900", "Fruits and Fruit Juices"],
  ["1000", "Pork Products"],
  ["1100", "Vegetables and Vegetable Products"],
  ["1200", "Nut and Seed Products"],
  ["1300", "Beef Products"],
  ["1400", "Beverages"],
  ["1500", "Finfish and Shellfish Products"],
  ["1600", "Legumes and Legume Products"],
  ["1700", "Lamb, Veal, and Game Products"],
  ["1800", "Baked Products"],
  ["1900", "Sweets"],
  ["2000", "Cereal Grains and Pasta"],
  ["2100", "Fast Foods"],
  ["2200", "Meals, Entrees, and Side Dishes"],
  ["2500", "Snacks"],
  ["3500", "American Indian/Alaska Native Foods"],
  ["3600", "Restaurant Foods"]

groups.each do |g|
  FoodGroup.first_or_create(FdGrp_Cd: g[0], FdGrp_Desc: g[1])

Additionally, if you’d like some rails models for your api, this might be a good start:

# app/models/food.rb
class Food < ActiveRecord::Base
  self.table_name = "food_des"
  self.primary_key = "NDB_No"

  has_many :measures, :foreign_key => "NDB_No"
  has_one :food_group, primary_key: "FdGrp_Cd", :foreign_key =>  "FdGrp_Cd"

# app/models/food_group.rb
class FoodGroup < ActiveRecord::Base
  self.table_name = "fd_group"

# app/models/measure.rb
class Measure < ActiveRecord::Base
  self.table_name = "weight"

  belongs_to :food, primary_key: "NDB_No", :foreign_key =>  "NDB_No"