1 / 110

認識 Shell Script 與 X Window System

認識 Shell Script 與 X Window System. 目錄. Shell Script 簡介 ……………………………8 Bourne Shell ………………10 Cshell ……………………………11 第一個 BaShell Script…16 執行 Shell Script……17 環境變數的取用 ………………18 取得參數 ………………………19 接受使用者輸入 ………………20 自訂變數 ………………………21. 目錄. Shell Script 變數的數學運算 ………………22 條件測試 ………………………23

lane-avery
Download Presentation

認識 Shell Script 與 X Window System

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 認識 Shell Script 與 X Window System

  2. 目錄 • Shell Script • 簡介……………………………8 • Bourne Shell ………………10 • Cshell ……………………………11 • 第一個BaShell Script…16 • 執行Shell Script……17 • 環境變數的取用………………18 • 取得參數………………………19 • 接受使用者輸入………………20 • 自訂變數………………………21

  3. 目錄 • Shell Script • 變數的數學運算………………22 • 條件測試………………………23 • 流程控制………………………26 • Shell Script 的練習…………27 • 迴圈………………………………28 • 迴圈練習………………………30 • 常用的擴充程式……………31 • Cron

  4. 目錄 • Cron • 什麼是cron……………………34 • Cron工作檔範例………………36 • Cron欄位代表意義…………37 • Cron範例……………………38 • 結合 cron 與 shell script……………………………………………41 • Linux 基本網路程式使用 • telnet……………………………42

  5. 目錄 • Linux 基本網路程式使用 • ftp……………………………45 • mail…………………………49 • ping…………………………52 • X Window System 介紹 • 歷史………………………………53 • 稱呼………………………………54 • XFree86…………………………55 • X Window System的特點……………………………56

  6. 目錄 • X Window System 運作原理 • 介紹………………………………63 • X server ………………………68 • X client ………………………76 • X protocol ……………………82 • Client/server架構的優點………………………………………91

  7. 目錄 • Client/server 架構效能考量……………………………………99 • 網路通透性…………………101 • X Window System 其它特性………………………………103 • 視窗管理程式………………105 • 各個視窗管理程式簡介………………………………110 本書X Window System 部份取材自旗標出版的【X Window 徹底研究】

  8. Shell Script • 什麼是Shell Script? • Shell Script 是shell指令的巨集,也是一種程式語言。 • Script 語言皆不需經過編譯(compiler) , 可以直接由命令解譯器直接執行。

  9. Shell Script • Shell Script 都是一樣的嗎? • No, 不同的Shell, 其script 也隨之不同。 • Ex: Bsh, Csh

  10. Shell Script • BourneShell • 是最早的Shell, 其script為BourneShell Script • 現在幾乎很少見, 因為已被Bash所取代 (BourneShell為基礎,強化出的新Shell).

  11. Shell Script • Cshell • Csh Script 是一種類似C語言語法的直述語言。 • 如同BourneShell一般, 已有更先進的Tcsh取而代之。

  12. Shell Script • Bash • 是目前Linux最常用的Shell • 其Script相容於BourneShell • 在Linux下, 已經完全以Bash取代BourneShell了。

  13. Shell Script • TcShell • 也是目前常用的Shell • 其Script相容於Cshell • Linux下已經完全取代Cshell.

  14. Shell Script • 為何要寫Shell Script • 我們希望一些常用的命令集能以一個命令取代。 • 用來處理一些特定的問題,如計算每月上網(PPP)總時數。

  15. Shell Script • Shell Script 需要用到什麼? • 文字編輯器 (用來編寫Script檔) • 命令解譯器 (EX: Csh, Bash) • 其他工具 (做為擴充Shell Script的功能, EX: grep, wc)

  16. Shell Script • 第一個 BaShell Script • #!/bin/bash • #My first shell-script • echo -n “How are you? “ • echo “I am “`who am i`

  17. Shell Script • 執行Shell Script • 1. • bash shell_script.txt • 2. • chmod 700 shell_script.txt • ./shell_script.txt

  18. Shell Script • 環境變數的取用 • #!/bin/bash • echo $PATH • echo “My Home is at “$HOME

  19. Shell Script • 取得參數 • #!/bin/bash • echo “The Command is “$0 • echo “You Have “$#” args” • echo “First args is “$1

  20. Shell Script • 接受使用者輸入 • #!/bin/bash • read name • echo “You typed “$name

  21. Shell Script • 自訂變數 • #!/bin/bash • x=1 • w=“strings” • echo x • echo w • y=“This is “$w”.”

  22. Shell Script • 變數的數學運算 • #!/bin/bash • x=x+1 • echo $x • y=`expr 1 + 1` • echo #y

  23. Shell Script • 條件測試 • #!/bin/bash • test 1 = 1 • echo $? • test 1 = 2 • echo $?

  24. Shell Script • 測試指令(test)更多方式: • test $a != $b • test $a • test $w -eq 1 • test $w -ne 1 • test $w -ge 1 • test $w -gt 1 • test $w -le 1 • test $w -lt 1

  25. Shell Script • 測試指令(test)更多方式: • test -d file • test -f file • test -s file • test -r file • test -w file • test -x file

  26. Shell Script • 流程控制: • if [ -f /boot/vmlinuz ] • then • echo “The file is exist” • else • echo “The file isn’t exist” • fi

  27. Shell script • 請設計一個shell Script 程式,功能如下: • 如果5分鐘內無人login進來, 就自動關機(shutdown)

  28. Shell Script • 迴圈(一): • for file in *.txt • do • echo $file • done

  29. Shell Script • 迴圈(二) • for var in 1 2 3 4 5 6 7 8 9 • do • echo $var • done

  30. Shell Script • 請設計一個Shell Script 程式,功能如下. • 九九乘法表 • p.s. 請注意螢幕換行問題。

  31. Shell Script • Shell Script 常會使用到的擴充程式: • grep (找關鍵字) • cat (顯示檔案內容) • tail (取出結尾) • head (取出標頭) • cut (取出特定範圍)

  32. Shell Script • 請設計一個Shell Script 程式,功能如下. • 計算網路每小時共傳送多少封包、接收多少封包,和發生幾次碰撞,並求出碰撞機率. • 公式: 碰撞/ (傳送+接收+碰撞)

  33. Shell Script • 請設計一個Shell Script 程式,功能如下. • 列出每次PPP上網時間 • 列出每次上網的電話費用 • p.s 一般時段, 1.7/5分 • 減價時段, 1/10分

  34. Cron • 什麼是Cron • 在指定時間讓系統為你做指定的工作 • Cron 只能被系統管理者(root)執行或更改。

  35. Cron • /var/spool/cron/crontabs/ • 此目錄中存放為不同使用者所做的Cron工作檔.

  36. Cron • 工作檔範例: • 0,5,10,15,20,25,30,35,40,45,50,55 * * * * /usr/lib/atrun 1> /dev/null 2> /dev/null • 40 04 * * * updatedb 1> /dev/null 2> /dev/null

  37. Cron • * * * * * 五個欄位分別代表: • 分 (min) • 時 (hour) • 日 (day) • 月 (mon) • 週 (week)

  38. Cron • 範例一: • 10 6 * * * Backup_shell_script • 每天早上 6:10 做系統備份

  39. Cron • 範例二: • 0 */2 * * * sync • 每兩小時執行sync

  40. Cron • 範例三: • 0 23-7/2,12 * * * sync • 從晚上 11:00 到早上 7:00, 每兩小時sync 一次, 但中午 12:00 也做 sync 一次.

  41. Cron • 將 Shell Script加上 Cron, 達成實用的結果: • Ex: 試做一個可以檢查上網時(PPP), 如果過了5分都沒有再接收或傳送封包,就自動斷線。

  42. Linux基本網路程式使用-telnet • telnet: • 遠端登入程式。 • 當我們想連線到網路上的電腦時,最常使用的程式

  43. Linux基本網路程式使用-telnet • 連線方法: • telnet <對方主機名稱或IP位址> • telnet <主機>:xxxx • 其中xxxx指特定的port,如果預設的port(23),被其他程式使用(如bbs)那麼就要用這種方法來遠端登入。 • 使用telnet 時,要有該主機的使用者帳號才可登入

  44. Linux基本網路程式使用-telnet • telnet • 操作方法: • 與一般登入機器時一樣。 • 離線方法: • 輸入‘exit’ • 輸入‘logout’ • 按【ctrl】+【d】 • 按【ctrl】+【]】,強制離線,之後再按一次【ctrl】+【d】

  45. Linux基本網路程式使用-ftp • ftp-檔案傳輸程式 • 從遠端主機擷取檔案或是將檔案存放到遠端主機時會用到

  46. Linux基本網路程式使用-ftp • 連線方法: • ftp <主機名稱或IP位址> • telnet <主機>:xxxx • 其中xxxx指特定的 port ,有些 ftp 站的 port 都有特殊指定過,那麼,就要使用此種方法來進入該主機。

  47. Linux基本網路程式使用-ftp • 操作方法 • 查詢指令: • ? • 列出目錄: • ls • dir • 切換檔案型態: • ascii • binary • 下載檔案: • get • 上傳檔案: • put

  48. Linux基本網路程式使用-ftp • 離線方法: • bye • 其它: • hash - 每傳 1024bytes 就會出現一個#符號,可用來觀察是否有斷線的情形發生。

  49. Linux基本網路程式使用-mail • 寄電子郵件用 • 寄信: 1.mail xxx@xxx.xxx.xxx 2. Subject :為該封信之標題 3.開始編寫內容 4.寫完之後,按【enter】,再按【.】,再按【enter】就可以寄出去了。 5.若是要拿某一個已經編輯好的檔案當信的內容時,只要鍵入:mail XX@xx.xx < 檔名 ,即可

  50. Linux基本網路程式使用-mail • 閱讀郵件: • 當有新信來的時候,系統會有訊息:You have new mail. • 鍵入 mail 就可以讀信了 • 在 mail 的提示符號(&)下,可以下指令: • 看信時只要鍵入該信的編號即可,如要看第一封,打1。 • 當看完一封信,要刪除它時,用d • 想刪除第一封到第五封,則用d 1-5 • 刪掉全部用d*

More Related