Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- #ssh module
- import paramiko
- '''remote/ssh to a pc(smsinfo.zain.co.ug) login
- to a postgres db
- execute a db querry
- return the result'''
- hostname = '192.1968.2.178'
- port = 22
- username = 'dokwii'
- password = 'okwi1478'
- #cmd = 'tail -f /tmp/mt_billing.log'
- sql = "select count(*) from mt_bill20110514 where status='t';"
- #create ssh object
- ssh = paramiko.SSHClient()
- ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
- #connect
- try:
- ssh.connect('smsinfo.zain.co.ug',username=username, password=password)
- except:
- print 'failed to connect to remote host'
- #now lets login to the db
- try:
- ssh.exec_command('psql kannel postgres')
- except:
- print 'failed to login to db'
- #now lets query the db
- try:
- stdin, stdout, stderr = ssh.exec_command(sql)
- db_count = stdout.read()
- print db_count
- except:
- print 'failed to querry db'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement