Skip to content

Instantly share code, notes, and snippets.

@bryanjswift
Created February 27, 2014 06:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bryanjswift/9245254 to your computer and use it in GitHub Desktop.
Save bryanjswift/9245254 to your computer and use it in GitHub Desktop.
Process STDIN containing DB row sets from a command selecting email address and password hash. Used in pipeline like `ssh {{ main_user_name }}@{{ domain }} 'PGPASSWORD={{ mail_db_password }} psql -U {{ mail_db_username }} -h 127.0.0.1 --command="SELECT email, password FROM virtual_users;" {{ mail_db_database }}' | grep '\$6\$' | ./mail_virtual_u…
#!/usr/bin/env ruby
require 'yaml'
# Part of command to sync down hashed user passwords
accounts = []
$stdin.each_line do |line|
email = line.split('|')[0].gsub(/\s+/, '')
hash = line.split('|')[1].gsub(/\s+/, '')
accounts << {
'account' => email.split('@')[0],
'domain' => email.split('@')[1],
'password_hash' => hash,
'domain_pk_id' => 1,
}
end
mail_virtual_users = { 'mail_virtual_users' => accounts }
$stdout.puts mail_virtual_users.to_yaml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment