Python / Psycopg2/PopstgreSQLとCronを使用します。リモートサーバー情報(以下を参照)を取得して、ホストコンピューターのPostGreSQLデータベースに追加したいと思います。
Using #!/usr/bin/python
import socket
import commands
import string
import os
hostname = socket.gethostname()
print hostname
ip = commands.getoutput("ifconfig").split("\n")[1].split()[1][5:]
print ip
os = commands.getoutput("lsb_release -d")
print os[13:34]
kernel = commands.getoutput("uname -p")
print kernel
reboot = commands.getoutput("who -b")
print reboot[22:38]
これは「データベースへの接続」スクリプトです。
#!/usr/bin/python
import psycopg2
import sys
try:
conn = psycopg2.connect('host=*** dbname=*** user=*** password=***')
print "Connected to Database"
except:
print "No Connection"
cur = conn.cursor()#cursor_factory=psycopg2.extras.DictCursor)
try:
cur.execute('SELECT * FROM new')
rows = cur.fetchall()
print "\n Show: \n"
for row in rows:
print " ", row
except:
print "Not Working"
接続でき、データをプルできます。2つのスクリプトを組み合わせて、返された情報をデータベースに挿入する必要があります。