Skip to content

Instantly share code, notes, and snippets.

@sentinelleader
Last active August 29, 2015 14:00
Show Gist options
  • Save sentinelleader/18700913ab4c657d229d to your computer and use it in GitHub Desktop.
Save sentinelleader/18700913ab4c657d229d to your computer and use it in GitHub Desktop.
#! /usr/bin/ruby
require 'net/ssh'
user_name = ARGV[0]
if user_name == NIL
abort("No username mentioned. command should run like ---> account_call_details.rb {plivo username}")
else
cmd_format_userid = %q(psql -U postgres plivo_cloud -F, --no-align -c "select id from auth_user where username=')
cmd_userid = cmd_format_userid + user_name + %q(';" | grep -v id | grep -v row)
ssh_dbcfg = Net::SSH.start('slave1.dbcfg.plivo.com', 'ruser')
user_id = ssh_dbcfg.exec!(cmd_userid)
cmd_format_accountid = %q(psql -U postgres plivo_cloud -F, --no-align -c "select id from plivo_account_account where user_id=')
cmd_accountid = cmd_format_accountid + user_id + %q(';" | grep -v id | grep -v row)
account_id = ssh_dbcfg.exec!(cmd_accountid)
ssh_dbcfg.close()
ssh_dblog = Net::SSH.start('slave1.dblog.plivo.com', 'ruser')
cmd_format_cdr = %q(psql -U plivolog plivo_cloud_logs --no-align -c "select start_time,end_time,to_number,from_number,call_direction,call_state,bill_duration from plivo_logs_calldetailrecord where account_id=')
cmd_cdr = cmd_format_cdr + account_id.chomp() + %q(' ORDER BY start_time DESC LIMIT 50;") + %q( | grep -v row)
puts ssh_dblog.exec!(cmd_cdr)
ssh_dblog.close()
end
@sentinelleader
Copy link
Author

Net::SSH gem is required for this script,

use "sudo gem install net-ssh"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment