#!/bin/bash export ORACLE_SID=orcl export ORACLE_BASE=/u01/app/oracle export ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1 export ORACLE_OWNR=oracle export PATH=$PATH:$ORACLE_HOME/bin if [ ! -f $ORACLE_HOME/bin/dbstart -o ! -d $ORACLE_HOME ] then echo "Oracle startup: cannot start" exit 1 fi case "$1" in start) # Oracle listener and instance startup echo -n "Starting Oracle: " su $ORACLE_OWNR -c "$ORACLE_HOME/bin/lsnrctl start" su $ORACLE_OWNR -c "$ORACLE_HOME/bin/dbstart $ORACLE_HOME" su $ORACLE_OWNR -c "$ORACLE_HOME/bin/emctl start dbconsole" su oracle -c "/u01/app/oracle/product/11.1.0/db_1/bin/emctl start dbconsole" touch /var/lock/oracle echo "OK" ;; stop) # Oracle listener and instance shutdown echo -n "Shutdown Oracle: " su $ORACLE_OWNR -c "$ORACLE_HOME/bin/lsnrctl stop" su $ORACLE_OWNR -c "$ORACLE_HOME/bin/dbshut $ORACLE_HOME" su $ORACLE_OWNR -c "$ORACLE_HOME/bin/emctl stop dbconsole" rm -f /var/lock/oracle echo "OK" ;; reload|restart) $0 stop $0 start ;; *) echo "Usage: `basename $0` start|stop|restart|reload" exit 1 esac exit 0
ORACLE Startup and Shutdown Script
更改sql developer 語系設定….
其實sqldeveloper是一個好物…在不用錢的狀況下:P
如果需要把他改變成english的話…只需要按照下面的方式修改…
~/sqldeveloper/sqldeveloper/bin/sqldeveloper.conf
把下列的設定加入到裏面去…
AddVMOption -Duser.language=en
AddVMOption -Duser.region=US
下次開sqldeveloper就會是english的了….
Alert Log for 11G
從11g開始…AlertLog開始變成了XML的格式,目的是方便其他軟體來分析LOG File…
for 10G
$oracle_home\admin\SID\bdump\alert.log
for 11G
SQL> select value from v$diag_info where name =’Diag Alert’;
VALUE
——————————————————————————–
/opt/oracle/diag/rdbms/orcl/orcl/alert
SQL> select value from v$diag_info where name =’Diag Alert’;
VALUE
——————————————————————————–
/opt/oracle/diag/rdbms/orcl/orcl/alert
SQL> select value from v$diag_info where name =’Diag Trace’;
VALUE
——————————————————————————–
/opt/oracle/diag/rdbms/orcl/orcl/trace
新年快樂…
揮別2009
2010對於我來說…又是另一個十年的開始,
上一次是2000年…那時候並不覺得怎麼樣…大概因為年紀的增長..覺得時間過越來越快…
某種程度上也算是越來越害怕吧…XDD
新年新希望…
希望我有Mac XDD
希望我有單眼..XDD
希望我一定能瘦到70kg….
希望我在32歲可以進G公司
希望今年一定能順利畢業…
希望….。。。。(以下銷音處理) XDD
下一個…十年是2020….屆時我就是一個4字頭的老頭了XDD
新年快樂….:P
daily system check and send mail
真的太懶了…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 re
__author__ = "AllenWang"
__copyright__ = "Copyright 2009, SYSTEM CHECK FOR MAIL REPORT Project"
__credits__ = "Allen Wang"
__license__ = "GPL"
__version__ = "1.0"
__maintainer__ = "Allen Wang"
__email__ = "allencswang@gmail.com"
__status__ = "Released"
def getstate(url, file):
'''GET INFORMATION FROM NAGIOS WEB SITE'''
#url = "http://nagios.XXXX.com/nagios/cgi-bin/status.cgi?hostgroup=dominoserver&style=detail"
#file = "system_state.txt"
wp = urllib.urlopen(url)
content = wp.read()
fp = open(file,"w")
fp.write(content)
fp.close()
return True
def replace(r_txt, r_url, data):
'''FIX HTML LINK '''
#r_url = 'http://nagios.XXXX.com/nagios/cgi-bin/status.cgi'
#r_txt = 'status.cgi'
pattern = re.compile(r_txt, re.IGNORECASE)
fp = open("tmp", "w")
for line in file(data):
fp.write(pattern.sub(r_url, line))
fp.close()
os.rename("tmp",data)
return True
def msend_html(server, strFrom, strTo, subject, file):
'''SEND MAIL'''
#Define these once; use them twice!
#strFrom = 'allen.wang@XXXX.com'
#strTo = 'allen.wang@XXXX.com'
#Create the root message and fill in the from, to, and subject headers
msgRoot = MIMEMultipart('related')
msgRoot['Subject'] = subject
msgRoot['From'] = strFrom
msgRoot['To'] = strTo
msgRoot.preamble = 'This is a multi-part message in MIME format.'
#Encapsulate the plain and HTML versions of the message body in an
#'alternative' part, so message agents can decide which they want to display.
msgAlternative = MIMEMultipart('alternative')
msgRoot.attach(msgAlternative)
msgText = MIMEText('This is the alternative plain text message.')
msgAlternative.attach(msgText)
#We reference the image in the IMG SRC attribute by the ID we give it below
fp = open(file, 'rb')
msgText = MIMEText(fp.read(), 'html')
msgAlternative.attach(msgText)
fp.close()
#This example assumes the image is in the current directory
#fp = open('test.jpg', 'rb')
#msgImage = MIMEImage(fp.read())
#fp.close()
#Send the email (this example assumes SMTP authentication is required)
smtp = smtplib.SMTP()
smtp.connect(server)
#smtp.login('exampleuser', 'examplepass')
smtp.sendmail(strFrom, strTo, msgRoot.as_string())
smtp.quit()
return True
def main():
url = "http://nagios.XXXX.com/nagios/cgi-bin/status.cgi?hostgroup=dominoserver&style=detail"
file = "system_state.txt"
r_url = 'http://nagios.XXXX.com/nagios'
r_txt = "/nagios"
getstate(url, file)
replace(r_txt, r_url, file)
r_url = 'http://nagios.XXXX.com/nagios/cgi-bin/status.cgi'
r_txt = 'status.cgi'
replace(r_txt, r_url, file)
r_url = 'http://nagios.XXXX.com/nagios/cgi-bin/extinfo.cgi'
r_txt = 'extinfo.cgi'
replace(r_txt, r_url, file)
localtime = time.strftime("%H:%M", time.localtime())
subject = 'The mail system daily report at %s' % (localtime)
msend_html('10.181.59.137', 'allen.wang@XXXX.com', 'allen.wang@XXXX.com', subject, file)
os.remove(file)
if __name__ == '__main__':
main()
python 讚啦…
搞定收工…:P
rman error
在有些Linux下會發生RMAN就給你錯誤訊息….rman: can’t open target
其原因是因為在Linux下有一個類似的程式叫作/usr/X11R6/bin/rman
所以你執行的根本就不是ORACLE的RMAN….XDD
修正方法把$ORACLE_HOME/bin的PATH放在/usr/X11R6/bin/之前即可…
export PATH=$ORACLE_HOME/bin:$PATH
這樣因該就可以開始快樂的RMAN了XDD
Oracle Client for Win7 64bit
這幾天苦惱於如何將Oracle Client裝在Win7上…
在Google大神的幫助下,終於找到方法可以安裝,不過….
這個方法只是pass他的檢查機制…並不是原廠所出的軟體…
作法如下…
修改refhost.xml檔案
<!–Microsoft Windows 7–>
<OPERATING_SYSTEM>
<VERSION VALUE=”6.1″/>
</OPERATING_SYSTEM>
搞定…
ps.如果在同一個目錄或是軟體有多個refhost.xml檔…都必須修改…
Check Spam Report
今天寫了一個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 fix sendmail problem
====================================
'''
import smtplib
import sys
import time
import commands
__copyright__ = "Copyright 2009, Check Spam Report Script"
__create_date__ = '2009/12/09 21:58'
__version__ = '2.2'
__author__ = 'Allen Wang'
__email__ = 'allencswang@gmail.com'
__credits__ = "Allen Wang"
__license__ = "GPL"
__maintainer__ = "Allen Wang"
__status__ = "Released"
def chklog(sent, chkcount, chktime):
cmd = 'cat /var/log/maillog |grep "%s" |grep "%s" |wc -l' % (sent, chktime)
localtime = time.strftime("%H:%M", time.localtime())
logcount = commands.getoutput(cmd)
if int(logcount) == 0:
emsg(logcount,localtime)
elif int(logcount) < int(chkcount):
emsg(logcount,localtime)
else:
print 'Check time: %s' % (localtime)
print 'Total sent %s spam report' % (logcount)
send_state(logcount,localtime)
def emsg(logcount,localtime):
print 'Check time: %s' % (localtime)
print 'please check you spam server,because only sent %s spam mail report' % (logcount)
localtime = time.strftime("%H:%M", time.localtime())
send_boxsol(logcount,localtime)
send_yageo(logcount,localtime)
def send_state(logcount,localtime):
msg = 'check time:%s \nTotal sent %s spam report' % (localtime,logcount)
subject = 'The Spam Report check state at %s, Total sent %s spam report' % (localtime,logcount)
contacts = ['xxx@xxx.xxx']
mail('xxx.xxx.xxx.xxx','xxx@xxx.xxx',contacts,subject,msg)
def send_boxsol(logcount,localtime):
msg = 'The spam report have problem at %s,because only sent %s spam report to YAGEO users, please check... message from YAGEO Allen mobile:0920576298' % (localtime,logcount)
subject = 'The Spam Report have problem, please check...'
contacts =['xxx@xxx.xxx.xxx','xxx@xxx.xxx.xxx','xxx@xxx.xxx.xxx','xxx@xxx.xxx']
mail('xxx.xxx.xxx.xxx','xxx@xxx.xxx',contacts,subject,msg)
def send_yageo(logcount,localtime):
msg = 'The spam report have problem at %s,because only sent %s spam report to YAGEO users, please check...' % (localtime,logcount)
subject = 'The Spam Report have problem, please check...'
contacts = ["xxx@xxx.xxx.xxx","xxx@xxx.xxx.xxx","xxx@xxx.xxx","xxx@xxx.xxx"]
mail('xxx.xxx.xxx.xxx','xxx@xxx.xxx',contacts,subject,msg)
def mail(serverURL=None, strFrom='', strTo='', subject='', text=''):
#headers = "From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n" % (strFrom, strTo, subject)
smtp = smtplib.SMTP()
smtp.connect(serverURL)
#smtp.login('exampleuser', 'examplepass')
#smtp.sendmail(strFrom, strTo, message)
for x in strTo:
headers = "From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n" % (strFrom, x, subject)
message = headers + text
#print x
smtp.sendmail(strFrom, x, message)
smtp.quit()
def main():
chklog(sent,chkcount,chktime)
if __name__ == '__main__':
sent = sys.argv[1]
chkcount = sys.argv[2]
chktime = sys.argv[3]
main()
FreeBSD 8 Released
稍早在網路上知道FreeBSD Released了…
也就順手把一台beta,升到released…
步驟如下,
setp 1
#cp /usr/share/examples/cvsup/stable-supfile /root/8release
#vi /root/8release
setp 2
*default host=cvsup.tw.FreeBSD.org
*default release=cvs tag=RELENG_8_0
ps.http://ftp.giga.net.tw/cvsup.php <<—CVSUP更新狀態.
setp3
#make installworld && make installkernel
#mergemaster
#reboot
Done…:P
