- さくらインターネットのレンタルサーバを使っている。
- 毎日mysqlのバックアップを自動的に取りたい。
- 一週間分だけ取っておきたい(一週間以上前のバックアップは消えてほしい)。
と、聞かれたので、書いておく。
- mysqldumpでダンプする。
- bzip2で圧縮する。
- dateで取得した曜日をファイル名に含めて毎日上書きする。
という方針でいく。
続きを読む
と、聞かれたので、書いておく。
という方針でいく。
続きを読む
OpenOffice.orgを2.3にバージョンアップした。
インストール自体はファイルサーバ上に一度だけで完了。ただ、ファイルの関連付けを変更するにはインストーラを動かさないといけない。
何台もあるサーバで関連付けを変えるためだけにインストーラを動かすのは面倒だなあ、ということで、ファイルの関連付けだけを登録、変更するバッチを作って移行完了。力技。
change user /install
pause
assoc .odb=opendocument.DatabaseDocument.1
assoc .odf=opendocument.MathDocument.1
assoc .odg=opendocument.DrawDocument.1
assoc .odm=opendocument.WriterGlobalDocument.1
assoc .odp=opendocument.ImpressDocument.1
assoc .ods=opendocument.CalcDocument.1
assoc .odt=opendocument.WriterDocument.1
assoc .otg=opendocument.DrawTemplate.1
assoc .oth=opendocument.WriterWebTemplate.1
assoc .otp=opendocument.ImpressTemplate.1
assoc .ots=opendocument.CalcTemplate.1
assoc .ott=opendocument.WriterTemplate.1
pause
ftype opendocument.CalcDocument.1="Z:\OpenOffice.org 2.3\program\scalc.exe" -o "%%1"
ftype opendocument.CalcTemplate.1="Z:\OpenOffice.org 2.3\program\soffice.exe" -o "%%1"
ftype opendocument.DatabaseDocument.1="Z:\OpenOffice.org 2.3\program\sbase.exe" -o "%%1"
ftype opendocument.DrawDocument.1="Z:\OpenOffice.org 2.3\program\sdraw.exe" -o "%%1"
ftype opendocument.DrawTemplate.1="Z:\OpenOffice.org 2.3\program\soffice.exe" -o "%%1"
ftype opendocument.ImpressDocument.1="Z:\OpenOffice.org 2.3\program\simpress.exe" -o "%%1"
ftype opendocument.ImpressTemplate.1="Z:\OpenOffice.org 2.3\program\soffice.exe" -o "%%1"
ftype opendocument.MathDocument.1="Z:\OpenOffice.org 2.3\program\smath.exe" -o "%%1"
ftype opendocument.WriterDocument.1="Z:\OpenOffice.org 2.3\program\swriter.exe" -o "%%1"
ftype opendocument.WriterGlobalDocument.1="Z:\OpenOffice.org 2.3\program\soffice.exe" -o "%%1"
ftype opendocument.WriterTemplate.1="Z:\OpenOffice.org 2.3\program\soffice.exe" -o "%%1"
ftype opendocument.WriterWebTemplate.1="Z:\OpenOffice.org 2.3\program\soffice.exe" -o "%%1"
pause
全員のデスクトップのショートカットを揃えたほうが電話でサポートしやすいね、ということで。
VBスクリプトを使ってショートカット作成スクリプトを作ってみた。
使い方は、こんな感じ。
C:\>create-shortcuts.vbs shortcut.conf
create-shortcuts.vbs
'#####################################################
' ショートカット作成スクリプト
' 設定ファイル複数受付版
'#####################################################
Const FOR_READING = 1
Const COL_FOLDER = 0
Const COL_SUB_FOLDER = 1
Const COL_TITLE = 2
Const COL_PATH = 3
Const COL_WORK = 4
Set objArgs = WScript.Arguments
'Wscript.Echo objArgs(0)
'Wscript.Echo objArgs.length
For arg_index = 0 to objArgs.length-1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile(objArgs(arg_index), FOR_READING)
Do Until objTextFile.AtEndOfStream
strNextLine = objTextFile.Readline
if strNextLine <> "" then
conf = Split(strNextLine , ",")
if conf(COL_FOLDER) <> "" then
Set Shell = CreateObject("WScript.Shell")
CreatePath = Shell.SpecialFolders(conf(COL_FOLDER))
if CreatePath = "" then CreatePath = conf(COL_FOLDER)
if conf(COL_SUB_FOLDER) <> "" then
CreatePath = CreatePath & "\" & conf(COL_SUB_FOLDER)
if not objFSO.FolderExists(CreatePath) then
objFSO.CreateFolder(CreatePath)
end if
end if
Set link = Shell.CreateShortcut(CreatePath & "\" & conf(COL_TITLE) &".lnk")
link.Description = conf(COL_TITLE)
link.HotKey = ""
link.IconLocation = conf(COL_PATH)
link.TargetPath = conf(COL_PATH)
'通常のウインドウ
link.WindowStyle = 1
link.WorkingDirectory = conf(COL_WORK)
args = ""
For i = COL_WORK+1 to Ubound(conf)
args = args & " " & conf(i)
Next
link.Arguments = args
ret = link.Save
'デバッグ情報
' Wscript.Echo "タイトル:" & conf(0)
' Wscript.Echo "パス:" & conf(1)
' Wscript.Echo "作業ディレクトリ:" & conf(2)
' Wscript.Echo "引数:" & args
' Wscript.Echo ret
end if
end if
Loop
Next
shortcut.conf
,******************************************** , カンマで始まる行はコメント行 ,******************************************** ,カンマで区切って、作成場所、タイトル,パス,作業ディレクトリ,引数1,引数2,引数3,...の順に書いておくと ,作成場所(デスクトップなど)にショートカットを作る ,作成場所に指定できるのは次のものだけ , AllUsersDesktop , AllUsersStartMenu , AllUsersPrograms , AllUsersStartup , Desktop , Favorites , Fonts , MyDocuments , NetHood , PrintHood , Programs , Recent , SendTo , StartMenu , Startup , Templates ,**************************************************************** , ここからが実際のデータ ,**************************************************************** Programs,,Excel,C:\Program Files\Microsoft Office\Office11\excel.exe,H:\, Programs,,Word,C:\Program Files\Microsoft Office\Office11\winword.exe,H:\, Programs,,PowerPoint,C:\Program Files\Microsoft Office\Office11\powerpnt.exe,H:\, Programs,,Visio,C:\Program Files\Microsoft Office\Visio10\visio.exe,H:\, Programs,,Access,C:\Program Files\Microsoft Office\Office11\msaccess.exe,H:\, Desktop,,Excel,C:\Program Files\Microsoft Office\Office11\excel.exe,H:\, Desktop,,Word,C:\Program Files\Microsoft Office\Office11\winword.exe,H:\, Desktop,,PowerPoint,C:\Program Files\Microsoft Office\Office11\powerpnt.exe,H:\, Desktop,,Visio,C:\Program Files\Microsoft Office\Visio10\visio.exe,H:\, Desktop,,Access,C:\Program Files\Microsoft Office\Office11\msaccess.exe,H:\,
Guidelines For Shipping Container Labeling http://www.bisg.org/docs/shipping_label_guidelines_09-2005.pdf
こんなのをやるにあたって、ちゃんとしたモジュラス10ウエイト3のチェックデジットを計算する必要があったので作った。
ついでに、isbnlib.pyよりもシンプルに10桁ISBNを13桁にする関数も。
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""モジュラス10ウエイト3とISBNのチェックデジット計算。Python版。
"""
def m10w31(code):
"""モジュラス10ウエイト3チェックデジットの計算
"""
s = list(str(code))
s.reverse()
sum = 0
w = 3
for i in s:
sum = sum + (int(i) * w)
if w == 3: w = 1
else: w = 3
d = sum % 10
if d<>0: d = 10 - d
return str(d)
def isbn10to13(isbn10):
"""10桁ISBNを13桁ISBNに変換
"""
s = '978'+isbn10[:9]
return s+m10w31(s)
def ssccBarCode(isbn13):
""" SSCC bar code
See, http://www.bisg.org/docs/shipping_label_guidelines_09-2005.pdf
"""
PRFX1='01'
PRFX2='1'
code = isbn13[:12]
return "(%s)%s %s-%s" % (PRFX1, PRFX2, code, m10w31(PRFX2+code))
if __name__=='__main__':
data = ('4770025364','4770023230','4770015419','4881359290','4883731626','4873112109')
for isbn10 in data:
isbn13 = isbn10to13(isbn10)
print " %s -> %s -> %s" % (isbn10,isbn13,ssccBarCode(isbn13))
function m10w31(code: string): integer;
/**
Delphi版 モジュラス10ウエィト3のチェックデジット計算。
*/
var
i,w,sum: integer;
begin
w := 3;
sum := 0;
for i := length(code) downto 1 do
begin
sum := sum + strtoint(code[i]) * w;
if w = 3 then w := 1
else w := 3;
end;
Result := sum mod 10;
if Result<>0 then Result := 10 - Result;
end;
今頃といえば今頃だけど、直近の仕事で使えそうなので。
tb.py
#!/usr/bin/env python2.4
# -*- coding: utf-8 -*-
"""トラックバックを受けて、テキストファイルに出力する。
"""
import os
DB='/tmp/tb.txt'
if not os.path.exists(DB):
f = file(DB,'w')
f.write('--- trackbacks ---\n')
f.close()
def resp(error_code=0,message=None):
s = "%d " % error_code
if message:
s += "%s " % message
return s
def xml_resp(s):
return """
%s
""" % s
class TrackbackRequest(object):
title = ""
url = ""
blog_name = ""
excerpt = ""
def __init__(self,form):
if form.has_key('title'):self.title = form['title'].value
if form.has_key('url'):self.url = form['url'].value
if form.has_key('blog_name'):self.blog_name = form['blog_name'].value
if form.has_key('excerpt'):self.excerpt = form['excerpt'].value
if not self.url:
raise Exception,"url should exists."
def save(self,file_name):
f = file(file_name,'a')
f.write('%s\t%s\t%s\t%s\n' % (self.url,self.title,self.blog_name,self.excerpt))
f.close()
import cgi
print "Content-type: text/xml\n"
try:
tb = TrackbackRequest(cgi.FieldStorage())
tb.save(DB)
print xml_resp(resp(0,str(tb)))
except Exception,msg:
print resp(1,msg)