Python script using django---MySQL write disk file system to database save

Source: Internet
Author: User
Tags null null python script

/usr/lib/python2.6/site-packages/django/contrib/admin/templates/admin/base_site.html# Modifying a login name

############################################

[[email protected] myweb]# python

Python 2.6.6 (r266:84292, Oct 12 2012, 14:23:48)

[GCC 4.4.6 20120305 (Red Hat 4.4.6-4)] on linux2

Type "Help", "copyright", "credits" or "license" for more information.

>>> Import OS

>>> Import Tab,sys

>>> sys.path.append ('/tmp/python/django-1.5.1/django/bin/myweb ')

>>> os.environ[' django_settings_module '] = ' myweb.settings '

>>> from pyweb.models import Publisher

>>> P1 = Publisher (name= ' xushanghai1 ', address= ' 24242 Chuansha Road ', city= ' Shanghai ', state_province= ' CN ', country= ' China ', website= ' http://www.xxk.com/')

>>> P1.save ()

#################################################### #写入数据库

#!/bin/usr/bin python

Import Os,datetime,paramiko

Import Tab,sys

Sys.path.append ('/tmp/python/django-1.5.1/django/bin/myweb ')

os.environ[' django_settings_module '] = ' myweb.settings '

From Pyweb.models import Filesystem

hosts=[' 192.168.1.10 ', ' 192.168.1.11 ', ' 192.168.1.13 ']

Username= ' Root '

Password= ' 123456 '

Port=22

For IPs in hosts:

If Os.system (' ping%s-c 1 '%ip) ==0:

Paramiko.util.log_to_file (' Paramiko.log ')

s = Paramiko. Sshclient ()

S.set_missing_host_key_policy (Paramiko. Autoaddpolicy ())

S.connect (Ip,port,username,password)

Stdin,stdout,stderr=s.exec_command (' DF-KP ')

Df= Stdout.read (). Split (' \ n ')

S.close ()

Else

df= ' nul \ n-null NULL NULL NULL NULL NULL \ n '. Split (' \ n ')

Time=datetime.datetime.now (). Strftime ('%y-%m-%d%h:%m:%s ')

# df=os.popen (' DF-KP '). Read (). split (' \ n ')

Df.pop (0)

Df.pop (-1)

For line in DF:


List=line.split ()

P1 = Filesystem (ip= '%s '%ip,date_time= '%s '%time,filesystem= '%s '%list[0], sum_kb= '%s '%list[1],used= '%s '%list[2],

Available= '%s '%list[3], capacity= '%s '%list[4],mounted_on= '%s '%list[5])

P1.save ()


#########################

Import datetime

Datetime.datetime.now (). Strftime ('%y-%m-%d%h:%m:%s ');


Python script using django---MySQL write disk file system to database save

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.