2014年2月25日 星期二

按鍵精靈在VM中輸入問題

自己測試的結果,由於VM擷取鍵盤,所以無法用saystring直接輸入字串,而必須使用KeyPress代替,並且可以使用變數。也幸好我要輸入的變數是數字,所以使用迴圈來輸入。

參考資料
迴圈
http://tw.knowledge.yahoo.com/question/question?qid=1508062208839
輸入@等組合鍵寫法
http://tw.knowledge.yahoo.com/question/question?qid=1612072311102

ubuntu菱形進不去系統,powerbutton直接關機,忽略錯誤及關閉自動檢查

出現F<10个菱形>I<8个菱形>S<8个菱形>M<6个菱形>時的解決方法

Press F to attempt to fix the errors, I to ignore, S to skip mounting, or M for manual recovery

出現 菱形 S 菱形 M 菱形

Press S to skip mount or M for manual recovery

進入terminal之後

輸入
export LC_ALL=en_US.UTF-8 (將語言改為英文就不會再出現菱形)
fsck.ext4 /dev/sda1 (改成你毀損的磁區)

可以使用tune2fs設定檢查時機
tune2fs -c 2 /dev/sda1
上述即為掛載兩次檢查fsck

可修改 /etc/default/rcS 內的FSCKFIX=yes可在fsck時自動yes修復不須確定

參考資料
http://forum.ubuntu.org.cn/viewtopic.php?t=386633&p=2848077
Powerbutton直接關機方法
1.- sudo gedit /etc/acpi/events/powerbtn
2.- Add # to comment line: #action=/etc/acpi/powerbtn.sh
3.- Add a new line: action=/sbin/poweroff
4.- Save file
5.- Open a console and type: sudo acpid restart
http://askubuntu.com/questions/66723/how-do-i-modify-the-power-options/84984#84984?newreg=f3d31f5e61b8490fb1d67db682319552
圖形加速
http://www.ubuntu-tw.org/modules/newbb/viewtopic.php?topic_id=71872
windows關機前執行指令
http://ithelp.ithome.com.tw/question/10114763?tag=rt.rq
windows忽略錯誤及關閉自動修復
bcdedit /set {default} recoveryenabled no
bcdedit /set {default} bootstatuspolicy ignoreallfailures
(bcdedit /set {default} bootstatuspolicy displayallfailures) 啟用
http://www.i-so.org/disable-windows7-startup-repair.html
ubuntu關閉磁碟檢查
要進入開機選單在啟動時按住SHIFT
http://crunchbang.org/forums/viewtopic.php?pid=190573
http://forums.linuxmint.com/viewtopic.php?f=90&t=97550
https://help.ubuntu.com/community/Grub2
http://bbs.csdn.net/topics/390190378?page=1#post-393687150
http://neicole.blog.51cto.com/5621716/975581
http://tobalatech.blogspot.tw/2009/12/ubuntu-grub2.html
http://kenchio.wordpress.com/2012/05/24/20120524/
http://marvell1001.blogspot.tw/2012/09/grub-200-ubuntu-1204.html
Press S to skip mount or M for manual recovery
http://unix.stackexchange.com/questions/46628/not-able-to-lock-var-lib-dpkg-lock-read-only
tune2fs
http://wiki.debian.org.hk/w/Configure_regular_filesystem_check
fsck -y
http://askubuntu.com/questions/151025/how-can-i-make-fsck-run-non-interactively-at-boot-time

cisco router

連接console
http://bubble727.pixnet.net/blog/post/6789747-%5Bcisco%5D%E8%B6%85%E7%B4%9A%E7%B5%82%E7%AB%AF%E6%A9%9F,-%E9%87%8D%E8%A8%AD%E9%81%BA%E5%A4%B1%E5%AF%86%E7%A2%BC%E7%9A%84cisco-router
http://www.james-tw.com/cisco/cisco-she-ding-yuan-duan-lian-xian-telnet-ssh

基本
http://www.netadmin.com.tw/article_content.aspx?sn=1208100002&jump=1
http://www.netadmin.com.tw/article_content.aspx?sn=1205070002&jump=2
http://giboss.pixnet.net/blog/post/26807628-cisco-router%E5%9F%BA%E6%9C%AC%E8%A8%AD%E5%AE%9A
http://www.dotblogs.com.tw/box5068/archive/2011/01/19/20896.aspx
http://eservice.seed.net.tw/class/class33.html
http://www.james-tw.com/cisco/cisco-switch-base-setting

gns3 switch
http://tanzih.blogspot.tw/2010/07/gns3switch.html
https://learningnetwork.cisco.com/docs/DOC-13824
https://www.youtube.com/watch?v=f868S9NnmHg
vlan
ghs3使用c3700模擬switch使用vlan時要連結到fastethernet1/x才可以,fastethernet0/x是屬於router部分指令會出錯
http://www.netadmin.com.tw/article_content.aspx?sn=1201100001
http://www.digininja.org/blog/gns_vbox_vlan_lab.php
http://blog.yam.com/gavint/article/31578943
http://www.hkitblog.com/?p=11273
兩個vlan互通
http://blog.xuite.net/ganpin917/home/38918407-%E5%88%A9%E7%94%A8Cisco+Router%E5%BB%BA%E7%BD%AEDHCP+Service

static ip
router基本上無法設定gateway,一般router可以設定default gateway是因為已經與switch合併,故當需要設定時可以當作switch使用
https://learningnetwork.cisco.com/thread/64528

dhcp
在分配IP時要將router介面設定ip並在dhcp default-router設定此ip
https://www.youtube.com/watch?v=P_H9BLP-MRw
http://wfeng520.blog.hexun.com.tw/80502133_d.html
jointlesscisco#show ip int brief
jointlesscisco(config-if)#ip address dhcp
jointlesscisco(config-if)#no shutdown
jointlesscisco(config)#ip domain-lookup
https://www.youtube.com/watch?v=tgJgUyja0XU

NAT
切換介面
Router1(config-if)#ip nat inside
切換介面
Router1(config-if)#ip nat outside
Router1(config)#access-list 1 permit any any
Router1(config)#ip nat inside source list 1 pool nat1 overload
http://blog.roodo.com/kennykao1976/archives/4751865.html
https://www.youtube.com/watch?v=FfPJ_dvM_is
http://www.hkitblog.com/?p=11027

full-duplex dismach
設定duplex auto即可
http://www.gossamer-threads.com/lists/cisco/nsp/135763

SDM
http://zenfei.blog.51cto.com/763386/392728

debug:
enable
config t
logging on
logging console debug
access-list 199 permit icmp any any
do debug arp
do debug ip pack deta 199
do ping 8.8.8.8 rep 1




  • #************************************************  
  • # telnet login routine  
  • #  
  • # @PARAMS  
  • # ipaddr - remote device ip address  
  • # user   - user name to login in  
  • # passwd - login password  
  • #  
  • # @RETURN  
  • # spawn_id if login success, otherwise 0  
  • #************************************************  
  •  proc login   
  • {  
  •  ipaddr user passwd  
  •  }  
  •  
  • {  
  •  global g_prompt g_usrPrompt g_pwdPrompt  
  •  
  •   spawn telnet $ipaddr  
  •   expect   
  •  {  
  •   "$g_usrPrompt"   
  •   {  
  •    exp_send "$user\r\n"  
  •     exp_continue  
  •    }  
  •   "$g_pwdPrompt"   
  •   {  
  •    exp_send "$passwd\r\n"  
  •     exp_continue  
  •    }  
  •   -ex "$g_prompt"   
  •   {  
  •    dbgLog "Login Successful\n"  
  •     return $spawn_id  
  •    }  
  •   timeout   
  •   {  
  •    send_user "timeout"  
  •     return 0  
  •    }  
  •  }  
  • 2014年1月13日 星期一

    copy.com&工作排程器使用vbs引數&相對路徑與使用效能監視器監視硬碟空間

    copy.com提供多個資料夾同步的功能,方法是將要同步的資料夾建立捷徑在copy資料夾內。
    相對路徑是指執行程式的位置,不是vbs指向的程式位置,要注意。而在工作排程器中則必須設定開始位置來定義相對路徑。

    NOTES:
    “Any Directory” Syncing. Okay, we totally make up this name but it is exactly how it sounds. While Dropbox limits us to sync only files in a central folder (aptly named Dropbox), Copy.com lets you sync any directories on your computer. You can do this by creating a shortcut to that folder and place it within Copy directory. Not very intuitive like SugarSync though, which lets us do exact same thing within right-click menu.

    Found a solution if any one is interested the only way it would take the parameters is by adding the path of the wscript to the scheduler to the run line in the scheduler. 
    Although wscript is the default for vbs files the scheduler would still ignore the parameters. 
    So to get it working the run text in the scheduler should be:

    C:\WINDOWS\system32\wscript.exe C:\TASKS\test.vbs one two

    I am not sure why this works when other methods dont but I have read that parameters are only passed to .exe files so this may be why they are ignored for .vbs files.

    Thanks for the help from KrisSimonis & dglienna.


    • Telnet is an extremely limited tool. A much better utility would be sc.exe (http://www.securityfocus.com/data/tools/nc11nt.zip). In a batch file you could use it like so:
      @echo off
      nc -z 81.6.53.245 1724
      if %ErrorLevel% EQU 0 (echo Port is open) else (echo Port is not open)
      While you could embed nc.exe in a VB Script file, this only complicates the matter.
      Alternatively, if you run Windows 7, portqry.exe could do a similar job.
      • Marked as answer by zsustar Thursday, July 29, 2010 8:11 AM
      Thursday, July 29, 2010 5:43 AM
      Avatar of Forest brook
      (MCC)
      19,605 Points
    • Portqry is helpful to my case because the parameter -q will
      returns 0 if port is listening
      returns 1 if port is not listening
      returns 2 if port is listening or filtered 
      And i draft a script as following~
      ***************
      Set WshShell = WScript.CreateObject("WScript.Shell")
      Return = WshShell.Run("PortQry.exe -nwww.google.com -p tcp -e 80 -q", 1, true)
      WScript.Echo Return
      *****************
      It's cool. Thank you Peqasus.
      BTW, nc.exe is not working, maybe it's killed by my Norton. Anyway i prefer the tools from MS in term of security control.


    會要這個功能,是因為我朋友反應說。硬碟空間不夠,就是要再買大容量的硬碟來換。但總不能等到磁碟空間都滿了才發現吧?所以,只好上網找一下 Solution 囉!
    因為之前已經做過利用 MailSend 這支小程式來發信,現在只要能夠找到觸發執行批次檔的方式就行了。
    上網看了有用 Power ShellVBScript 來做的,不過,我想我還是兜一下好了。所以,就利用「效能監視器」的「警示」功能囉!
    第一個動作,當然是先寫一下 batch 檔囉!因為我有切三個磁區,所以就分別監控囉!先利用 psinfo.exe -d 來檢視各磁碟的狀況。
    因為對 Linux 比較熟,所以就習慣用剩餘空間百分比來做觸發條件囉!但因為三個磁區的容量差異還蠻大的,經換算後,就以空間剩 85%90%97% 來做為觸發條件。
    列一下我所寫的 batch 檔:
    echo Volume Type  Format     Label                            Size            Free          Free > C:\sch\alarmhdd_c.txt
    C:\pstools\psinfo.exe -d |find "C: Fixed" >> C:\sch\alarmhdd_c.txt
    rem 郵件標題:伺服器C磁碟使用率達 85%
    C:\sch\mailsend -d msa.hinet.net -smtp mail.domain.com.tw -t admin@domain.com.tw -f hddcheck@hinet.net -sub "=?UTF-8?B?5Ly65pyN5Zmo77yj56OB56Kf5L2/55So546H6YGUIDg177yF?=" -m C:\sch\alarmhdd_c.txt
    因為 E-Mail 主旨有中文,怕有編碼上的問題,就利用網路上有線上轉換 Base64 的網頁,進行 Base64 編碼的動作。
    收到信的內容就大概如下:

    (這是測試用的,所以在未達 85% 也會寄發)
    接下來就是到「效能監視器」的「警示」來進行「新增警示設定」的動作。
    輸入一個警示名稱,本例為「DriveCAlarm」。
    在「註解」欄位寫入說明,再按下「新增」鈕。
    依照下列的圖示進行「計數器」項目的挑選,完成後按下「新增」鈕,再按「關閉」鈕。
    計數器欄位已經設定好了,接下來就是設定觸發條件。我對C磁區的設定為可用空間小於 5.86GB 就發出告警,1天檢查1次。
    切換到「執行」頁籤,除了預設勾選的第一項外,再勾選「執行以下程式」。按下「瀏覽」鈕,挑選要執行的 Batch 檔,本例為:C:\sch\DriveCAlarm.bat
    按下「套用」鈕後,會出現「設定密碼」的視窗,使用者欄位格式要為「Domain\User」。
    確認一下「執行身分」是為之前所設定的「Domain\User」。
    這樣子「警示」功能就多了一項設定。如果未啟動,就將它啟動。有問題的話,就到事件檢視器看看訊息。
    為了要測試設定是否可運作?所以進行了下列的修改來確認。
    在事件檢視器中,就可以看到類似下面的事件訊息。當然也會收到 E-Mail
    大功告成,記得要將觸發條件改回來,要不然信就收不完啦!DE 磁區的設定也依樣畫葫蘆即可。


    [Tip]使用效能監視器監控伺服器狀態,並寄送異常通知

      
    當我們在管理伺服器時,常常會希望能監控伺服器狀態, 如果伺服器發生CPU持續過高,或是硬碟空間不足時能夠發出異常通知, 我們可以透過Windows內建的效能監視器來簡單實現這樣的功能。

    設定效能監視器異常界線

    在這邊以監控硬碟有效空間來做為範例。
    1. 首先打開我們的效能監視器,新增資料收集器集合工具
    2. 輸入名稱"伺服器效能監控",選擇使用手動建立
    3. 選擇"效能監視器警訊
    4. 我們可以看到已經出現了這個資料收集器集合
    5. 接下來開始新增我們的監控項目,新增一個資料收集器
    6. 輸入硬碟空間監控,並選擇效能計數器警訊
    7. 點選新增,選擇監控項目
    8. 選擇Logical Disk的% Free space,新增要監控的磁區
    9. 設定在20%以下時觸發警訊
    10. 勾選設定警訊內容

    設定效能監視器警訊執行動作

    1. 設定抽樣間格為2分鐘 (普通應該一小時即可)
    2. 點選警訊動作頁籤,勾選在事件紀錄檔紀錄
    3. 設定發生異常時執行排程及通知訊息,點選右邊小箭頭可以瀏覽可使用的變數

    設定發送警訊通知排程

    1. 進入工作排程器,新增排程工作
    2. 設定執行帳號,選擇不論是否登入都執行
    3. 點選動作頁籤,選擇新增
      當伺服器發生異常時,
    4. 輸入寄送email的資訊,$(Arg0)會自動帶入從效能監視器剛剛設定的警訊文字
    5. 設定完成,當伺服器異常時就會收到通知的Email了
    ※註: 使用內建的傳送電子郵件,僅支援不需驗證的SMTP Server, 此處可自由置換其他的警訊通知方法 (ex.Powershell) 只要記住可使用$(Arg0)來讀取帶入的警訊內容即可

    總結


    透過效能監視器,我們可以根據自己的需要實現簡單的伺服器監控機制, 當然隨著伺服器數量越來越多,可以按照需求使用更好的解決方案, 這邊提供大家一個簡單且輕量級的伺服器監控方法, 關於今天的內容,若有任何問題歡迎大家提出來一起討論!

    參考資料
    http://olivetjournal.com/my-honest-copy-com-review#proreviewhttp://forums.codeguru.com/showthread.php?439916-How-to-run-a-very-long-SQL-statementhttp://social.technet.microsoft.com/Forums/scriptcenter/en-US/37c5fced-38e4-4508-82a3-7e59cafce46f/how-to-use-vbscript-to-check-telnet-result?forum=ITCG

    http://blog.xuite.net/jyoutw/xtech/62155589
    http://www.dotblogs.com.tw/kirkchen/archive/2012/11/24/use-performance-monitor-to-monitor-server-and-send-alert-email.aspx


    Xpath, xml 轉成http並且擷取需要的nodes, unicode編碼問題,vba轉vbs, bat讀入變數,篩選及比對

    使用Xpath抓取xml內的資料

    Set objXMLHTTP = CreateObject("Microsoft.XMLHTTP")
                objXMLHTTP.Open "Get", "xml網址", False
                  objXMLHTTP.setRequestHeader "Content-Type", "text/xml"
                    objXMLHTTP.setRequestHeader "charset", "UTF-8"
                      objXMLHTTP.Send

          testXML = objXMLHTTP.responseText

          Set objXMLHTTP = Nothing

          接著要注意的是XPath 2.0要加上第二行否則有些語法不能使用

          Set xmldoc = CreateObject("MSXML2.DOMDocument")
                  xmldoc.setProperty "SelectionLanguage", "XPath"
                  
                  xmldoc.LoadXML (testXML)

          Count node數量

          Set Root = xmldoc.DocumentElement.SelectSingleNode("篩選條件")
                    
                   xmlcount = xmldoc.DocumentElement.SelectNodes("篩選條件").Length

          接著篩選的方法
          格式是路徑//channel/item/title[(contains(.,'條件')],左式是指篩選符合條件的title層級,須注意路徑要依照xml內的格式填寫,並且可以使用and和or

          如果需要新增或開啟檔案需要呼叫檔案系統物件

          Set objfso = CreateObject("Scripting.FileSystemObject")

          我在寫的時候遇到亂碼的問題,因此調用ADODB.Stream

          Set objtextfile = CreateObject("ADODB.Stream")

                          objtextfile.Charset = "utf-8"
                          objtextfile.Open
                          objtextfile.LoadFromFile ("檔案路徑")

          寫入檔案時使用

          objtextfile.writetext xmldoc.DocumentElement.SelectNodes("篩選條件").Item(i).text + Chr(13) + Chr(10)

          + Chr(13) + Chr(10)是換行的意思

          另外如果要比對字串

          Set d = CreateObject("Scripting.Dictionary")

          Do Until objtextfile.EOS
                          arr = objtextfile.ReadText(-2)
                          d.Add arr, arr
                          Loop

          EOS是讀到檔案結尾,然後將objtextfile的內容寫入Dictionary d內
          最後如果比對Dictionary跟檔案有不同的時候寫入檔案

          If Not d.Exists(Cel) Then
          fs.writetext
          end if

          bat讀入每行變數,使用%%a

          for /f %%a in (檔案.txt) do (動作,將輸入變數用%%a替代)

          參考資料
          Xpath, xml 轉成http並且擷取需要的nodes
          http://www.blueshop.com.tw/board/FUM200410061525290EW/BRD2011041810155910R.html
          http://bytes.com/topic/xml/answers/895475-how-do-i-get-value
          http://bbs.csdn.net/topics/360192227
          http://www.w3school.com.cn/xml/xml_to_html.asp
          http://michaelbaidotnet.blogspot.tw/2012/05/xpathxml-xmldocument-xmlnode-xml.html
          http://stackoverflow.com/questions/247135/using-xpath-to-search-text-containing
          http://stackoverflow.com/questions/3655549/xpath-containstext-some-string-doesnt-work-when-used-with-node-with-more
          http://www.pin5i.com/showtopic-23231.html
          http://zhidao.baidu.com/question/494955221.html
          http://web2.tcssh.tc.edu.tw/teacher/cjwu/vb/newvb6/new0g05.html
          http://msdn.microsoft.com/zh-tw/library/1k5e45de(v=vs.90).aspx
          http://stackoverflow.com/questions/7986679/classic-asp-not-recognizing-xpath-contains-function
          http://stackoverflow.com/questions/17049535/vbscript-taking-xml-node-values-and-assigning-to-variables
          http://stackoverflow.com/questions/14469414/xpath-selecting-same-level-node-with-different-name
          http://stackoverflow.com/questions/3139402/how-to-select-following-sibling-xml-tag-using-xpath
          unicode編碼問題
          http://www.blueshop.com.tw/board/show.asp?subcde=BRD20110626172457CS9&fumcde=FUM200501271723350KG&odr=cdt&odrtyp=0
          http://www.dotblogs.com.tw/rainmaker/archive/2011/05/17/25261.aspx
          http://stackoverflow.com/questions/2524703/save-text-file-utf-8-encoded-with-vba
          http://tw.knowledge.yahoo.com/question/question?qid=1607092206104
          vba轉vbs
          http://www.asjh.tn.edu.tw/xupload/learning/vbscript/vbs16.htm
          http://www.visualbasicscript.com/Vbscript-to-read-txt-file-for-input-m31649.aspx
          http://www.itworld.com/nl/win_this_wk/04282003
          http://www.visualbasicscript.com/m57228-print.aspx
          http://mikenation.net/files/backupprintservers.txt
          bat讀入變數
          http://www.dotblogs.com.tw/chhuang/archive/2012/06/09/72702.aspx
          rss feed在chrome顯示亂碼
          http://blog.hsdn.net/1388.html
          讀入字串亂碼使用ADODB.Stream解決
          http://baike.baidu.com/view/1806836.htm
          http://www.lotusfans.com/forum/archive/index.php/t-43645.html
          http://stackoverflow.com/questions/15151128/read-large-file-line-by-line-with-ado-stream
          http://stackoverflow.com/questions/13851473/read-utf-8-text-file-in-vbscript