- HTML、CSS、Javascript & jQuery
- Misc
var VariableName[ = "Value"]; |
if (<Boolean Expression>) { .........; .........; } |
// 單行註解 /* 多 行 註 解 */ |
<head> <script language="javascript"> ...............; ...............; </script> </head> |
ListName=[Item1,Item2,Item3....] |
[Item1,Item2,Item3....] |
Code Meaning ------------------------------------------- s String (or any object’s str(X) string) r s, but uses repr, not str c Character d Decimal (integer) i Integer u Same as d (obsolete: no longer unsigned) o Octal integer x Hex integer X x, but prints uppercase e Floating-point exponent, lowercase E Same as e, but prints uppercase f Floating-point decimal F Floating-point decimal g Floating-point e or f G Floating-point E or F % Literal % |
'%[flags][width][.precision]typecode' %(Value) |
#整數 >>> '%d' %(77) '77' #%+<typecode > : 加正負號 >>> '%+d %+d' %(100,-100) '+100 -100' #%<Width><typecode > : 控制輸出位數 >>> '%4d %6d %2d' %(100,100,100) ' 100 100 100' #%<0Width><typecode > : 控制輸出位數,不足位補'0' >>> '%04d %06d %02d' %(100,100,100) '0100 000100 100' #%<-Width><typecode > : 控制輸出位數,向左靠攏 >>> '%4d %6d %2d' %(100,100,100) ' 100 100 100' >>> '%-4d %-6d %-2d' %(100,100,100) '100 100 100' |
#浮點數 >>> '%f' %(100.123) '100.123000' #%+<typecode > : 加正負號 >>> '%+f %+f' %(100.123,-100.123 ) '+100.123000 -100.123000' #%<Width.Precidion><typecode > : 控制輸出位數 >>> '%6.3f %2.2f' %(100.123,100.123 ) '100.123 100.12' #%<0Width.Precidion><typecode > : 控制輸出位數,不足位補'0' >>> '%07.3f %08.3f' %(100.123,100.123 ) '100.123 0100.123' #%<-Width.Precidion><typecode > : 控制輸出位數,向左靠攏 >>> '%08.3f %-8.3f' %(100.123,100.123 ) '0100.123 100.123 ' |
>>> '%2.2f' %(100.125) '100.12' |
'%(key)[flags][width][.precision]typecode' %{key:Value} |
>>> '%(key1)d %(key2)f' %{"key1":123,"key2":123.321} '123 123.321000' |
'{FieldName}'.format(Value) |
'{Position} {Keyword}}'.format(PValue,,Keyword=KValue) |
>>> '{0} {1}'.format('string',1.23) 'string 1.23' >>> '{Keyword1} {Keyword2}'.format(Keyword1=3.21,Keyword2='KValue') '3.21 KValue' >>> '{0} {Keyword}'.format('String',Keyword='KValue') 'String KValue' |
>>> 'Dic&Pos {0[Key]}'.format({"Key":'Value'}) 'Dic&Pos Value' |
>>> 'Dic&Keyword {Keyword[Key]}'.format(Keyword={"Key":'KValue'}) 'Dic&Keyword KValue' |
>>> '{} {}'.format('string',1.23) 'string 1.23' |
>>> List=('LVaule1','LVakue2') >>> List ('LVaule1', 'LVakue2') >>> Tuple=['TVaule1','TVakue2'] >>> Tuple ['TVaule1', 'TVakue2'] >>> String='AString' >>> String 'AString' >>> 'String={2[2]} Tuple={1[1]} List={0[0]}'.format\ ... (List,Tuple,String) 'String=t Tuple=TVakue2 List=LVaule1' |
>>> 'String={2} Tuple={1} List={0}'.format \ ... (List[0:1],Tuple[1:2],String[2:3]) "String=t Tuple=['TVakue2'] List=('LVaule1',)" #在輸出的位置『Slice』會發生『ValueErroe』的例外 >>> 'String={2[2:3]} Tuple={1[1:2]} List={0[0:1]}'.format \ ... (List,Tuple,String) Traceback (most recent call last): File " |
'{FieldName!ConverFlag:FormatSpec}'.foramt(<Value>) |
[Align][0][Width][.Precidion][TypeCode] |
#只設定總寬度,預設會靠右對齊 >>> '{0:10}.format(100.123) ' 100.123' #未指定『TypeCode』浮點數會以指數形表示 >>> '{0:10.2}'.format(100.123) ' 1e+02' #加上『TypeCode』 >>> '{0:10.2f}'.format(100.123) ' 100.12' #未設定小數部份位數,浮點數的小數部份會補『0』 >>> '{0:10f}'.format(100.123) '100.123000' >>> '{0:010f}'.format(100.123) '100.123000' #要在整數部份補『0』要設定小數的位數 >>> '{0:010.2f}'.format(100.123) '0000100.12' #整數的三種對齊方式 >>> '{0:<10} {1:^10} {2:>10}'.format(66,77,88) '66 77 88' >>> '{0:<010} {1:^010} {2:>010}'.format(66,77,88) '6600000000 0000770000 0000000088' #浮點數的三種對齊方式 >>> '{0:<10.2f} {1:^10.2f} {2:>10.2f}'.format(12.3,12.3,12.3) '12.30 12.30 12.30' >>> '{0:<010.2f} {1:^010.2f} {2:>010.2f}'.format(12.3,12.3,12.3) '12.3000000 0012.30000 0000012.30' #thousand-separator syntax for numbers >>> '{0:,d}'.format(12345678) '12,345,678' >>> '{0:15,f}'.format(12345678.9123) '12,345,678.912300' >>> '{0:15,.4f}'.format(12345678.9123) '12,345,678.9123' |
(Item1 , Item2 , Item3,....) |
tupleName = (Item1 , Item2 , Item3,....) |
定義Tuple >>> demoTuple=(1,2,3,'a','B','Ayana','satomi') 印出整個Tuple >>> print demoTuple (1, 2, 3, 'a', 'B', 'Ayana', 'satomi') 印出第二個元素 >>> print demoTuple[1] 2 印出最後一個元素 >>> print demoTuple[-1] satomi >>> |
定義整數物件 >>> x=123 定義另一個 Tuple >>> otherTuple=(1,2,3,4) 合併 >>> demoTuple+(x,otherTuple) (1, 2, 3, 'a', 'B', 'Ayana', 'satomi', 123, (1, 2, 3, 4)) |
if <Boolean Expression 1>: suite_1 elif <Boolean Expression 2>: suite_2 elif <Boolean Expression 3>: suite_3 ................ ................ ................ else: Default_suite |
<Var = Value_A> if <Boolean Expression> else <Value_B> |
<Var = Value_A> if not <Boolean Expression> else <Value_B> |
check = Value print({Value1:OutputInfo1, Value2:OutputInfo2, Value3:OutputInfo3, ................... ................... ValueN:OutputInfoN}[check]) |
while <Boolean Expression>: while suite else: else suite |
for <Target> in <Object>: for suite else: else suite |
for <ControlVariable> in <Object>: suite |
for <ControlVariable> in <Object>: suite |
>>> for I in 'Iteration': print I ... I t e r a t i o n |
>>> for I in ['Iteration1','Iteration2','Iteration3']: print I ... Iteration1 Iteration2 Iteration3 |
>>> for I in ('Iteration1','Iteration2','Iteration3'): print I ... Iteration1 Iteration2 Iteration3 |
$ python -V Python 2.7.1+ $ which python /usr/bin/python |
$ sudo apt-get install python3 $ python -V Python 2.7.1+ $ python3 -V Python 3.2 $ which python /usr/bin/python $ which python3 /usr/bin/python3 |
#!/usr/bin/python |
#!/usr/bin/env python |
#!/usr/bin/python3 |
#!/usr/bin/env python3 |
chmod +x <ScriptName> |
$ /PATH/.../<ScriptName> |
$ ./<ScriptName> |
$ python <ScriptName> |
$ python3 <ScriptName> |
#!/usr/bin/python3 # #『 #』之後的文字都會被視為註解文字 # ''' 從這一行開始 之間所有的文字都會被視為註解文字 ''' 到這一行結束 """ 這樣 也是 多行 註解 """ |
#-*- coding: utf-8 -* |
$ python notest.py File "notest.py", line 3 SyntaxError: Non-ASCII character '\xe4' in file notest.py on line 3, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details $ python3 notest.py 中文註解測試 |
String1 = 'String Object' |
變數賦值...... VariableName = <Vaule> 其實就是建立『Object reference(物件參照)』 Object reference = <Vaule> |
Compound Statement:suite |
virsh # pool-list --all 名稱 狀態 自動啟動 ----------------------------------------- default 啟用 yes image 啟用 yes VM-Image 啟用 yes Iso 非啟用中 yes |
virsh # vol-create-as --format qcow2 VM-Image test.qcow2.img 8G Vol test.qcow2.img created |
max@riyu:~$ kvm-img create -f qcow2 /media/SDA3/VmImage/disk.qcow2.img 8G Formatting '/media/SDA3/VmImage/disk.qcow2.img', fmt=qcow2 size=8589934592 encryption=off cluster_size=0 |
virsh # vol-list VM-Image 名稱 Path ----------------------------------------- test.qcow2.img /media/SDA3/VmImage/test.qcow2.img |
max@riyu:~$ virt-install \ > --connect qemu:///system \ > --name=Test \ > --vcpus=1 \ > --arch=x86_64 \ > --ram=1024 \ > --os-type=linux \ > --virt-type=kvm \ > --cdrom=/media/SDC7/001.LinuxISO/ubuntu-10.04.3-server-amd64.iso \ > --disk path=/media/SDA3/VmImage/test.qcow2.img,size=8 \ > --force \ > --network bridge=br0,model=virtio \ > --vnc --vncport=5900 Traceback (most recent call last): File "/usr/lib/python2.6/logging/handlers.py", line 71, in emit if self.shouldRollover(record): File "/usr/lib/python2.6/logging/handlers.py", line 144, in shouldRollover msg = "%s\n" % self.format(record) File "/usr/lib/python2.6/logging/__init__.py", line 648, in format return fmt.format(record) File "/usr/lib/python2.6/logging/__init__.py", line 439, in format s = self._fmt % record.__dict__ UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position 1: ordinal not in range(128) Starting install... Creating domain... 0 B 00:00 Unable to connect to graphical console: virt-viewer not installed. Please install the 'virt-viewer' package. Domain installation still in progress. You can reconnect to the console to complete the installation process. |
X11Forwarding
』將從 VM Server 透過 VNC 連到 VM quest 的畫面送到我的筆電。X11Forwarding
』。max@minako:~$ ssh -X max@10.0.0.100 |
max@riyu:~$ vinagre localhost:5900 |
X11Forwarding
』,所以『vinagre』的執行畫面會送回筆電。virsh # list Id 名稱 狀態 ---------------------------------- 6 Test 執行中 |
#!/bin/bash #DailyBackUpV201109210305.sh #備份筆電中的重要資料 #Verio:3.0 #Time:201109210305 #Max Lin max@mpsstudio.org #定義變數 LogFile="$HOME/BackUpLog/DailyBackUp.log" RemoteHost="10.128.0.100" TEMPDir="/tmp/DocBack" LXDETEMPDir=""$TEMPDir"/LXDE" ScriptTEMPDir=""$TEMPDir"/Script" DocTEMPDir=""$TEMPDir"/Doc" MyPassWord="1979576" MyAccount="亞利安人" MountHomeDir='/home/max/sharedir' LocalMountDir=""$MountHomeDir"/100DocBackup" RemoteHostMountOption="rw,noperm,nosuid,username="$MyAccount",password="$MyPassWord",iocharset=utf8,codepage=cp950" LXDEBackDir="/home/max/.config/lxpanel/LXDE/" ScriptBackDir="/home/max/Script" DocMountPoint="/media/DATABack" DocBackDir=""$DocMountPoint"/002.文件/" #Start #確認遠端備份主機連線狀態 ping -c 2 $RemoteHost > /dev/null ConnectCheck=$? #確認備份儲存目錄是否已掛載 mount | grep "100DocBackup" > /dev/null RemoteHostMountCheck=$? if [ $RemoteHostMountCheck -ne '0' ] ; then #掛載遠端文件備份掛載目錄 echo "$MyPassWord" | sudo -S mount -t cifs //"$RemoteHost"/DocBackup "$LocalMountDir" -o "$RemoteHostMountOption" RemoteHostMountCheck=$? else RemoteHostMountCheck=0 fi if [ $ConnectCheck -eq '0' -a $RemoteHostMountCheck -eq '0' ]; then echo "`date '+%Y%m%d'` ---- 備份作業開始 --------" >> $LogFile echo "`date '+%Y%m%d'` ==== 備份開始時間`date '+%H:%M:%S'`" >> $LogFile #備份LXDE設定檔 mkdir -p "$LXDETEMPDir" tar jcvf "$LXDETEMPDir"/LXDEConfigBackUp`date '+%Y%m%d'`.tar.bz2 "$LXDEBackDir" LXDETar=$? cp -r "$LXDETEMPDir"/* "$LocalMountDir" LXDECpCheck=$? if [ $LXDETar -eq '0' -a $LXDECpCheck -eq '0' ] ; then echo "`date '+%Y%m%d'` LXDE設定檔備份作業完成~~~" >> $LogFile else echo "`date '+%Y%m%d'` LXDE設定檔備份作業未完成!!!!" >> $LogFile fi #備份Script mkdir -p "$ScriptTEMPDir" tar jcvf "$ScriptTEMPDir"/ScriptBackUp`date '+%Y%m%d'`.tar.bz2 "$ScriptBackDir" ScriptTar=$? cp -r "$ScriptTEMPDir"/* "$LocalMountDir" ScriptCpCheck=$? if [ $ScriptTar -eq '0' -a $ScriptCpCheck -eq '0' ] ; then echo "`date '+%Y%m%d'` Script備份作業完成~~~" >> $LogFile else echo "`date '+%Y%m%d'` ScriptCpCheck備份作業未完成!!!!" >> $LogFile fi #文件備份 mkdir -p "$DocTEMPDir" mount | grep "$DocMountPoint" DocMountPointCheck=$? if [ $DocMountPointCheck -eq '0' ] ; then tar jcvf "$DocTEMPDir"/DocBackUp`date '+%Y%m%d'`.tar.bz2 "$DocBackDir" DocTar=$? cp -r "$DocTEMPDir"/* "$LocalMountDir" DocCpCheck=$? else echo "$MyPassWord" | sudo -S mount -t ext4 /dev/sda4 "$DocMountPoint" ReMountCheck=$? if [ $ReMountCheck -eq '0' ] ; then tar jcvf "$DocTEMPDir"/DocBackUp`date '+%Y%m%d'`.tar.bz2 "$DocBackDir" DocTar=$? cp -r "$DocTEMPDir"/* "$LocalMountDir" DocCpCheck=$? DocMountPointCheck=0 else DocMountPointCheck=1 fi fi if [ $DocMountPointCheck -eq '0' -a $DocTar -eq '0' -a $DocCpCheck -eq '0' ]; then echo "`date '+%Y%m%d'` Doc備份作業完成~~~" >> $LogFile else echo "`date '+%Y%m%d'` Doc備份作業未完成!!!!" >> $LogFile fi #刪除暫存目錄 rm -rf $TEMPDir #刪除遠端備份目錄中三天前的備份檔 find ""$LocalMountDir"/" -type f -mtime +3 -exec rm -f {} \; #確認文件備份目錄是否還掛載著 mount="$DocMountPoint" DocMountPointCheck=$? if [ $DocMountPointCheck -eq '0' ] ; then #卸載遠端備份目錄 echo "$MyPassWord" | sudo -S umount "$DocMountPoint" fi #確認備份儲存目錄是否仍掛載 mount | grep "$LocalMountDir" > /dev/null RemoteHostMountCheck=$? if [ $RemoteHostMountCheck -eq '0' ] ; then #卸載遠端備份目錄 echo "$MyPassWord" | sudo -S umount "$LocalMountDir" fi echo "`date '+%Y%m%d'` ==== 備份結束時間`date '+%H:%M:%S'`" >> $LogFile echo "`date '+%Y%m%d'` >>>> 備份作業完成 <<<<<<<<" >> $LogFile else echo "`date '+%Y%m%d'` 遠端備份目錄離線中或無法掛載遠端儲存設備,備份作業未開始!!!!" fi |
#!/bin/bash # # DefaultGatewayCheck.sh # # 自動設定我要的 Default Gateway # Version:2.0 # 201109190237 # Max Lin max@mpsstudio.org # #!/bin/bash # Checketh0=`route -n | grep "UG"| grep "eth0"` Checkwlan0=`route -n | grep "UG"| grep "wlan0"` if [ "$Checketh0" ] ; then echo '28825252' | sudo -S route del default gw 10.128.0.1 fi if [ ! "$Checkwlan0" ] ; then echo '28825252' | sudo -S route add default gw 10.0.0.1 fi |
1.檢視現有 Routing Table max@minako:~$ route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0 169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 eth0 10.0.0.0 0.0.0.0 255.128.0.0 U 2 0 0 wlan0 10.128.0.0 0.0.0.0 255.128.0.0 U 1 0 0 eth0 0.0.0.0 10.0.0.1 0.0.0.0 UG 0 0 0 wlan0 沒有『動物機群網段』的『DefaultGateway』 2.加上『動物機群網段』的『DefaultGateway』到 Routing Table max@minako:~$ sudo route add default gw 10.128.0.1 3.確認一下 max@minako:~$ route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0 169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 eth0 10.0.0.0 0.0.0.0 255.128.0.0 U 2 0 0 wlan0 10.128.0.0 0.0.0.0 255.128.0.0 U 1 0 0 eth0 0.0.0.0 10.128.0.1 0.0.0.0 UG 0 0 0 eth0 0.0.0.0 10.0.0.1 0.0.0.0 UG 0 0 0 wlan0 『動物機群網段』的『DefaultGateway』在 Routing Table 中 4.執行 Script max@minako:~$ ./CheckGw.sh 5.看一下Routing Table max@minako:~$ route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0 169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 eth0 10.0.0.0 0.0.0.0 255.128.0.0 U 2 0 0 wlan0 10.128.0.0 0.0.0.0 255.128.0.0 U 1 0 0 eth0 0.0.0.0 10.0.0.1 0.0.0.0 UG 0 0 0 wlan0 『動物機群網段』的『Default Gateway』沒了 6.刪掉『一般主機網段』的『Default Gateway』 max@minako:~$ sudo route del default gw 10.0.0.1 max@minako:~$ route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0 169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 eth0 10.0.0.0 0.0.0.0 255.128.0.0 U 2 0 0 wlan0 10.128.0.0 0.0.0.0 255.128.0.0 U 1 0 0 eth0 一筆『Default Gateway』都沒有 7.再跑一下Script max@minako:~$ ./CheckGw.sh max@minako:~$ route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0 169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 eth0 10.0.0.0 0.0.0.0 255.128.0.0 U 2 0 0 wlan0 10.128.0.0 0.0.0.0 255.128.0.0 U 1 0 0 eth0 0.0.0.0 10.0.0.1 0.0.0.0 UG 0 0 0 wlan0 嗯.....有效 |
$ java -version java version "1.6.0_22" OpenJDK Runtime Environment (IcedTea6 1.10.2) (6b22-1.10.2-0ubuntu1~11.04.1) OpenJDK 64-Bit Server VM (build 20.0-b11, mixed mode) |
$ sudo update-java-alternatives -s java-6-sun [sudo] password for max: max@minako:~$ java -version java version "1.6.0_26" Java(TM) SE Runtime Environment (build 1.6.0_26-b03) Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02, mixed mode) |
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games" |
JAVA_HOME="/usr/lib/jvm/java-6-sun" PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/lib/jvm/java-6-sun/bin" CLASSPATH=".:/usr/lib/jvm/java-6-sun/lib:/usr/lib/jvm/java-6-sun/lib/dt.jar:/usr/lib/jvm/java-6-sun/lib/tools.jar" |
$ echo $CLASSPATH .:/usr/lib/jvm/java-6-sun/lib:/usr/lib/jvm/java-6-sun/lib/dt.jar:/usr/lib/jvm/java-6-sun/lib/tools.jar max@minako:~$ echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/lib/jvm/java-6-sun/bin max@minako:~$ echo $JAVA_HOME /usr/lib/jvm/java-6-sun |
<!-- customized header contents --> <{$xoops_module_header}> </head> <body id="<{$xoops_dirname}>" class="<{$xoops_langcode}>"> <!-- Start Header --> <table cellspacing="0"> <tr id="header"> <td id="headerlogo"><a href="<{xoAppUrl /}>" title="<{$xoops_sitename}>"><img src="<{xoImgUrl xoops-logo.png}>" alt="<{$xoops_sitename}>" /></a></td> <td id="headerbanner"><{$xoops_banner}></td> </tr> <tr> <td id="headerbar" colspan="2"> </td> </tr> </table> <!-- End header --> |
<{if $xoops_uname == '特定帳號' }> <a href="<{xoAppUrl 想要出現的連結}>" style="text-decoration:none" target="_self"><font color="#3367FF">[ 連結顯示名稱 ]</font></a> <{/if}> |
<{if $xoops_uname }> 歡迎詞 !!! <{/if}> |
$ ssh max@192.168.1.100 |
b. 新增存放目錄
$ mkdir -p /media/SDA3/VmImage $ mkdir -p /media/SDA3/Iso |
c.使用『virsh』定義VM image 檔 及 OS 的iso檔的存放目錄
virsh pool-define-as <Name> <Format> - - - - "Path |
$virsh pool-define-as |
$virsh pool-define-as |
$ virsh pool-list --all 名稱 狀態 自動啟動 ----------------------------------------- default 啟用 yes image 啟用 yes TcViewLite 啟用 yes Iso 非啟用中 no VM-Image 非啟用中 no |
$ virsh pool-start VM-Image Pool VM-Image started $ virsh pool-start Iso Pool Iso started $ virsh pool-autostart VM-Image Pool VM-Image marked as autostarted $ virsh pool-autostart Iso Pool Iso marked as autostarted $ virsh pool-list --all 名稱 狀態 自動啟動 ----------------------------------------- default 啟用 yes image 啟用 yes Iso 啟用 yes TcViewLite 啟用 yes VM-Image 啟用 yes |