Execute MySQL Query from linux prompt (not db prompt)

Here’s a clean way to execute MySQL query without evening getting into the DB. Saves a step. But what is important here is that the password for the DB is generated via a script which can be used to connect to the DB.

mysql -uroot -p`python -c "from common_utils import common_lib; print common_lib.mysql_passwd()"` -D dbName -e "select tenant_hostname from tenant_ids"

Similarly, executing a DB backup by getting the password from a script result can be done as follows:

mysqldump -hlocalhost -uroot -p`python -c "from common_utils import common_lib; print common_lib.mysql_passwd()"` dbName tableName --result-file="/tmp/results.sql"

Update table with JOIN on another

I had to selectively updat a table in postgres by doing a JOIN on another table. Here’s an example of the schema and data that I needed to push:

table_system
id | installation_id | region | appliance_role

table_tenant
id | installation_id | host_controller

UPDATE table_system s
SET  region = 'US-West'
FROM table_tenant t
WHERE trim(t.host_controller) IN ('server-10.domain.com', 'server-11.domain.com')
AND t.installation_id = s.installation_id   -- USED For the JOIN
AND s.appliance_role='H';

Python – PUT data to a URL (Edit docusign recipient)

Wanted to submit a PUT request to a URL. The requests module in Python is the one recommended to do so. Can be easily downloaded using:

pip install requests

or

easy_install requests

More ways to install: http://docs.python-requests.org/en/latest/user/install/#install

Post installation, here’s a snippet to PUT data to a URL (this specific example shows how to Edit an existing docusign recipient):

#/usr/bin/python
import sys, json, urllib, urllib2, requests
import base64
 
# enter your info:
username = "username@org.com"
password = "YouP@ssword"
integratorKey = "YOUR-integration-key"

authenticateStr = "<DocuSignCredentials>" \
                    "<Username>" + username + "</Username>" \
                    "<Password>" + password + "</Password>" \
                    "<IntegratorKey>" + integratorKey + "</IntegratorKey>" \
                    "</DocuSignCredentials>"

# STEP 1 - Login
url = 'https://demo.docusign.net/restapi/v2/accounts/191919/envelopes/39d236e6-647c-4dac-b1ca-4b37b3ef9254/recipients'
payload = {
  "signers" :
  [
    {
      "email": "newrecipient@org.com",
      "name": "New Recipient",
      "recipientId": "2"
    }
  ]
}
headers = {'X-DocuSign-Authentication': authenticateStr, 'Accept': 'application/json'}
req = requests.put(url, data = json.dumps(payload), headers=headers)
print req
print req.status_code
print req.content

apt-get update errors on debian server – signature couldn’t be verified because the public key is not available

I was running into Warnings and Errors while executing an apt-get update on a debian server.

W: GPG error: http://ftp.us.debian.org squeeze Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY AED4B06F473041FA NO_PUBKEY 64481591B98321F9
W: GPG error: http://security.debian.org squeeze/updates Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY AED4B06F473041FA
W: GPG error: http://ftp.us.debian.org squeeze-updates Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 8B48AD6246925553

In computers based on a Debian operating system that uses Linux kernel, error messages may come up like ‘NO_PUBKEY’.This happens while using the Apt-Get command line tool and this error is associated with the tool’s update feature. The new feature in the Apt-Get package management tool guarantees the authenticity of the server before updating the Debian OS. That’s why the error ‘NO_PUBKEY’ pops up. This problem can be solved by keying in the appropriate commands. The fix for this is to re-download the keys using the hexidecimal numbers given in the error.

apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 64481591B98321F9 AED4B06F473041FA 8B48AD6246925553

You should see a similar looking out put

Executing: gpg --ignore-time-conflict --no-options --no-default-keyring --secret-keyring /etc/apt/secring.gpg --trustdb-name /etc/apt/trustdb.gpg --keyring /etc/apt/trusted.gpg --primary-keyring /etc/apt/trusted.gpg --keyserver keyserver.ubuntu.com --recv-keys 64481591B98321F9 AED4B06F473041FA 8B48AD6246925553