Wondering how life would be much easier if you could get the query resultset to be a dictionary and you could get the value by using a keyword on the dictionary. psycopg2 by default returns resultset as a tuple so you have to use row, etc to get the values. In order to use row[‘column_name’] from the result, you’ll have to use the extras module provided in the psycopg2. Initiate the cursor accordingly and you’ll be able to get the results in form of dictionary.
DB_CONNECTION_STRING = "host=%s dbname=%s user=%s password=%s" % (DB_HOST, DB_DATABASE, DB_USER, DB_PASSWORD)
dbConn = psycopg2.connect(DB_CONNECTION_STRING)
cur = dbConn.cursor(cursor_factory = psycopg2.extras.DictCursor)
qSelect = "SELECT server, data, report_date FROM kw_server_raw WHERE processed = FALSE"
results = cur.fetchall()
for row in results:
Had to research various sources to come up with the solution that would convert a date/time in string format and convert it to UTC timestamp.
import calendar, time, datetime
dt = '20150219000000' #-- The time in format YYMMDDHHMMSS
print calendar.timegm(datetime.datetime.strptime(dt, '%Y%m%d%H%M%S').utctimetuple()) #-- Should get you 1424304000
If you use a bash script to sftp/ssh into a remote terminal, you’ll notice the sftp prompt show up on the screen and the scripts beyond sftp will not be executed. You can enclose the remote server scripts in an EOM statement like this in order to do what you intend to.
#-- Go to the bottle server directory and get the existing files into the tars directory
tar -cvf /home/varun.verma/backups/provisioning-tars/bottle_server.tar *
tar -xvf bottle_server.tar
You can execute a shell script via an alias using the “source” syntax:
alias pushgs='source /home/varun.verma/scripts/shell/pushToGs.sh'
It took quite a while to figure this out. Eventually – the issue I was having was that I tried to install the standard AWS Ubuntu image. Search for community images with Ubuntu Desktop. After launching this instance, setup a user with sudo access (if you prefer to grant sudo) and install xrdp on the system (apt-get install xrdp). That’s it. Use the standard RDP client to login to the Ubuntu machine like you’ve seen before.
Here’s what I did on a Ubuntu EC2
A) Login as root using the keypairs (ssh -i key.pem firstname.lastname@example.org)
B) Setup the necessary users and their passwords with
C) Edit /etc/ssh/sshd_config setting
D) Restart the sshd with
# sudo service sshd restart
Quite a few steps are required to turn on RDP on Ubuntu instance installed on AWS. Here are the steps:
Step 1: Install Updates
# sudo apt-get update
# sudo apt-get upgrade
Step 2: Install XRDP Packages
# sudo apt-get install xrdp
Step 3: Restart the Machine
# sudo shutdown -r now
Step 4: Install xfce 4 desktop
# sudo add-apt-repository ppa:xubuntu-dev/xfce-4.10
# sudo apt-get update
# sudo apt-get install xfce4
Step 5: Configure xfce
# echo xfce4-session >~/.xsession
# sudo service xrdp restart
Step 6: Create a User account
# sudo adduser UserName
Step 7: Add Security Group rule to enable RDP on Incoming
Ports Protocol Source launch-wizard-2
3389 tcp 0.0.0.0/0 ✔
Step 8: Connect to remote machine.
On the welcome screen, click “Use default config”
Here’s the link to the original article: http://www.sysads.co.uk/2014/02/connect-ubuntu-server-13-10-amazon-ec2-xrdp/