By Allen, on December 29th, 2009%
真的太懶了…XDD,基本上當系統多到一定程度的時候,就因該進化到異常管理與通知….
人在怎麼勤快,一定會有懶散的時候…
這時候就是想想辦法讓電腦幫我們檢查個個系統的狀態與回報的時候,
前提:你已經裝好Nagios….:P
因Nagios…沒有report的功能…所以我就用python做了一個把網頁轉寄出去的功能…以應付老闆XDD
#!/usr/bin/env python
#-*- coding: utf-8 -*-
”’
===== Check Spam Report Script =====
Log:
2009/12/20 10:42 ver 0.1 Create Script “The mail system daily check”
2009/12/20 15:40 ver 0.5 add css in the daily report
2010/01/04 14:00 ver 1.0 fix all html link in mail
====================================
”’
from subprocess import call
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
from email.MIMEImage import MIMEImage
import os
import sys
import urllib
import smtplib
import time
import . . . → Read More: daily system check and send mail
By Allen, on December 9th, 2009%
今天寫了一個script來協助daily check…
沒用到太高級的方法,只是把事情搞定而已….
python,真是一個好物啊…:D
#!/usr/bin/env python
#-*- coding: utf-8 -*-
”’
===== Check Spam Report Script =====
Log:
2009/12/09 21:58 ver 1.0 Create Script
2009/12/10 13:30 ver 1.1 add localtime
2009/12/11 ver 1.5 add if spam reboot count is equal 0 send massage
2009/12/12 16:02 ver 2.0 The spam report state sent to system
2009/12/29 11:20 ver 2.1 improve send mail in python function
2010/02/02 11:00 ver 2.2 . . . → Read More: Check Spam Report
By Allen, on October 1st, 2009%
#!/usr/bin/python
import py_compile
import sys
file=raw_input(“Please enter your . . . → Read More: Python compile
By Allen, on September 18th, 2009%
#!/usr/bin/env python
#-*- coding: utf-8 -*-
”’
============================================
LOG
Date:2009/09/24
Add Threading Process
Date:2009/11/10
Add Check PATH, if you forget enter ‘/’
============================================
”’
import threading
import Queue
import os
import sys
import time
__author__ = “AllenWang”
__copyright__ = “Copyright 2009, SVN Backup Script”
__credits__ = “Allen Wang”
__license__ = “GPL”
__version__ = “1.0″
__maintainer__ = “Allen Wang”
__email__ = “allencswang@gmail.com”
__status__ = “Released”
queue = Queue.Queue()
def chkpath(_chk):
i = len(_chk) -1
if . . . → Read More: Backup_SVN.py
By Allen, on September 17th, 2009%
#!/usr/bin/env python
#-*- coding: utf-8 -*-
from subprocess import call
import sys
import time
import commands
source = “xxx@10.181.59.137:~/sysbackup/”
target = “~/sysbackup/relay/”
rsync = “/usr/local/bin/rsync”
arguments = “-avuzb –delete -e”
ssh = “‘ssh -i /home/xxx/.ssh/id_dsa’”
cmd = “%s %s %s %s %s” % (rsync, arguments, ssh, source, target)
def sync():
while True:
ret = call(cmd, shell=True)
. . . → Read More: rsync.py
By Allen, on September 16th, 2009%
只是為了偷懶,所以隨手寫了一個script…
#!/usr/bin/env python
#-*- coding: utf-8 -*-
import os
import commands
def usbdisk():
S_usb = commands.getoutput(‘df |grep /mnt/bkusb’)
if ‘/mnt/bkusb’ in S_usb:
print ‘usb disk relly to use’
return True
else:
. . . → Read More: automount.py
By Allen, on June 29th, 2009%
#!/usr/bin/env python
#-*- coding: utf-8 -*-
#System Admin tools library
#ver 0.1 by AllenWang 2009/06/29
import socket
import sys
import time
import commands
class ConnectedTest():
def CoTest(self, address, port):
s = socket.socket()
try:
s.connect((address,port))
. . . → Read More: admintools.py
By Allen, on June 29th, 2009%
#!/usr/bin/env python
#-*- coding: utf-8 -*-
import socket
import sys
class Connected_Test():
def CoTest(self, address, port):
s = socket.socket()
try:
s.connect((address,port))
. . . → Read More: Connected_Test.py for OOP
By Allen, on June 13th, 2009%
.vimrc
set shiftwidth=4
set tabstop=4
set expandtab
說明:
shiftwidth: 使用 [>>] , [< <] , cindent 時填入的空白數
tabstop:一個 tab 其長度相當於多少個空白
expandtab:將 . . . → Read More: Vim setting with python
By Allen, on June 12th, 2009%
#!/usr/bin/env python
#-*- coding: utf-8 -*-
import MySQLdb
import mailbox
dbhost=”127.0.0.1″
database=”xxxx”
sqluser=”xxxx”
sqlpassword=”xxxx”
db = MySQLdb.connect(host=dbhost, user=sqluser, passwd=sqlpassword, db=database , charset=”utf8″)
cursor = db.cursor()
param = []
sql = “insert into `maildate`.`mail` (`id`, `to`, `from`, `subject`, `received`, `date`, `message`) values(NULL, %s, %s, %s, %s, %s, NULL)”
for message in mailbox.mbox(‘/var/test’):
_to = message['to']
_from = message['from']
_subject . . . → Read More: Mail to Mysql