/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