Troubleshooting Linux Servers | sadservers | 刷題記錄 | Easy

更新於 發佈於 閱讀時間約 10 分鐘

Overview

Easy共有九題,所有難度總共有75題,慢慢更新中。


1."Saint John": what is writing to this log file?

Scenario: "Saint John": what is writing to this log file?

Level: Easy

Type: Fix

Access: Public

Description: A developer created a testing program that is continuously writing to a log file /var/log/bad.log and filling up disk. You can check for example with tail -f /var/log/bad.log.

This program is no longer needed. Find it and terminate it.

Test: The log file size doesn't change (within a time interval bigger than the rate of change of the log file).

The "Check My Solution" button runs the script /home/admin/agent/check.sh, which you can see and execute.

Time to Solve: 10 minutes.

  1. tail用於查看文件的末尾內容。-f參數是「follow」的縮寫,讓tail命令保持開啟狀態,並即時顯示文件的最新新增內容。
tail -f /var/log/bad/log
raw-image
  1. lsof 命令用於顯示系統中已打開的文件和這些文件的相關信息。使用 grep 來過濾包含 "/var/log/bad/log" 字串的信息。
lsof | grep "/var/log/bad/log"
# 得知PID為584
raw-image


  1. kill 命令用於向指定的進程發送終止信號,讓該進程正常結束。**584**為PID
kill 584
raw-image


  1. 使用相同指令查看沒有再繼續寫入資料
tail -f /var/log/bad/log

2."Saskatoon": counting IPs.

Scenario: "Saskatoon": counting IPs.

Level: Easy

Type: Do

Description: There's a web server access log file at /home/admin/access.log. The file consists of one line per HTTP request, with the requester's IP address at the beginning of each line.

Find what's the IP address that has the most requests in this file (there's no tie; the IP is unique). Write the solution into a file /home/admin/highestip.txt. For example, if your solution is "1.2.3.4", you can do echo "1.2.3.4" > /home/admin/highestip.txt

Test: The SHA1 checksum of the IP address sha1sum /home/admin/highestip.txt is 6ef426c40652babc0d081d438b9f353709008e93 (just a way to verify the solution without giving it away.)

Time to Solve: 15 minutes.

  1. 計算指定文件 /home/admin/access.log 中的行數
wc -l /home/admin/access.log
raw-image


  1. 顯示文件 /home/admin/access.log 的前五行內容
head -5 /home/admin/access.log
raw-image


  1. 使用 cut 命令來從文件 access.log 中提取字段第一欄(f1),然後使用 -d 設定分隔符為破折號('-'),最後使用 > iplist.txt 將提取的字段保存到名為 iplist.txt 的文件中
cd /home/admin 
#切換到工作目錄

cut -f1 access.log -d '-' > iplist.txt
#將IP提取出來存到iplist.tx

head -5 iplist.txt
# 列出前五行檢查結果
raw-image


  1. 使用 cat 命令輸出 iplist.txt 的內容,通過管道 | 傳遞給 sort 命令對ip進行排序,最後使用 > ip_order.txt 將排序後的結果保存到 ip_order.txt 文件中
  • 因為uniq無法偵測重複行,除非它們彼此相鄰[1]。因此,在使用 uniq之前必須對文件中的內容進行排序 sort
cat iplist.txt | sort > ip_order.txt

head -10 ip_order.txt
# 列出前十行檢查結果
raw-image


  1. 使用uniq命令用於刪除連續重複的行,-c 會顯示每行重複出現的次數。sortuniq 的輸出進行排序,以便使用tail顯示排序後的結果的最後10行。
uniq -c ip_order.txt | sort | tail -10

echo "66.249.73.135" > /home/admin/highestip.txt
#依照題目指示將答案寫入到/home/admin/highestip.txt
raw-image
  1. 送出答案
raw-image

[1] https://www.geeksforgeeks.org/uniq-command-in-linux-with-examples/?ref=header_search#:~:text=Note%3A%20uniq%20isn%E2%80%99t%20able%20to%20detect%20the%20duplicate%20lines%20unless%20they%20are%20adjacent%20to%20each%20other.%20The%20content%20in%20the%20file%20must%20be%20therefore%20sorted%20before%20using%20uniq%20or%20you%20can%20simply%20use%20sort%20%2Du%20instead%20of%20uniq%20command.%C2%A0


3."Santiago": Find the secret combination

Scenario: "Santiago": Find the secret combination

Level: Easy

Type: Do

Description: Alice the spy has hidden a secret number combination, find it using these instructions:

  1. Find the number of lines with occurrences of the string Alice (case sensitive) in the *.txt files in the /home/admin directory
  2. There's a file where Alice appears exactly once. In that file, in the line after that "Alice" occurrence there's a number.

Write both numbers consecutively as one (no new line or spaces) to the solution file. For example if the first number from 1) is 11 and the second 22, you can do echo -n 11 > /home/admin/solution; echo 22 >> /home/admin/solution or echo "1122" > /home/admin/solution.

Test: Running md5sum /home/admin/solution returns d80e026d18a57b56bddf1d99a8a491f9(just a way to verify the solution without giving it away.)

Time to Solve: 15 minutes.

  1. 切換至工作目錄
pwd
cd /home/admin/
ls -l
raw-image


  1. 使用 grep 命令在所有 .txt 的文件中搜尋包含字符串 'Alice' 的行, -c 參數計算匹配的行數
grep -c 'Alice' *.txt
# 相加為411(第一題答案)
raw-image


  1. 使用 grep 命令來在文件 1342-0.txt 中搜尋包含字符串 'Alice' 的行,並接著顯示每個匹配行的後一行(-A1)
grep -A1 'Alice' 1342-0.txt
# 得到下一行出現的數字156(第二題答案)
raw-image


  1. 提交答案
echo '411156' > /home/admin/solution
raw-image

留言
avatar-img
留言分享你的想法!
avatar-img
Marcos的方格子
20會員
44內容數
歡迎來到「Marcos的方格子」!目前在「Marcos談科技」撰寫在職涯上學習到的知識,在「Marcos談書」分享我在日常的閱讀和心得,歡迎您的到來!!
Marcos的方格子的其他內容
2024/12/21
可觀測性(Observability)是現代架構中的核心能力,透過指標、日誌和分散式追蹤三大支柱,幫助開發者深入理解系統狀態並快速定位問題根源。本篇文章回顧 DevOps Taiwan Meetup 的精彩內容,解析可觀測性與監控的差異、建置流程的四大階段,以及實務應用中的工具選擇與導入時機!
Thumbnail
2024/12/21
可觀測性(Observability)是現代架構中的核心能力,透過指標、日誌和分散式追蹤三大支柱,幫助開發者深入理解系統狀態並快速定位問題根源。本篇文章回顧 DevOps Taiwan Meetup 的精彩內容,解析可觀測性與監控的差異、建置流程的四大階段,以及實務應用中的工具選擇與導入時機!
Thumbnail
2024/12/14
本篇文章針對 CKA 認證考試中常見的實作題目,提供詳細解題流程與指令範例。內容基於 examtopic 題目解析,幫助考生掌握實作技能與應試技巧,快速提升 Kubernetes 操作能力,為通過 CKA 考試做好萬全準備!
Thumbnail
2024/12/14
本篇文章針對 CKA 認證考試中常見的實作題目,提供詳細解題流程與指令範例。內容基於 examtopic 題目解析,幫助考生掌握實作技能與應試技巧,快速提升 Kubernetes 操作能力,為通過 CKA 考試做好萬全準備!
Thumbnail
2024/09/17
如何一年內考取 Google Cloud 所有雲端證照
Thumbnail
2024/09/17
如何一年內考取 Google Cloud 所有雲端證照
Thumbnail
看更多
你可能也想看
Thumbnail
「欸!這是在哪裡買的?求連結 🥺」 誰叫你太有品味,一發就讓大家跟著剁手手? 讓你回購再回購的生活好物,是時候該介紹出場了吧! 「開箱你的美好生活」現正召喚各路好物的開箱使者 🤩
Thumbnail
「欸!這是在哪裡買的?求連結 🥺」 誰叫你太有品味,一發就讓大家跟著剁手手? 讓你回購再回購的生活好物,是時候該介紹出場了吧! 「開箱你的美好生活」現正召喚各路好物的開箱使者 🤩
Thumbnail
介紹朋友新開的蝦皮選物店『10樓2選物店』,並分享方格子與蝦皮合作的分潤計畫,註冊流程簡單,0成本、無綁約,推薦給想增加收入的讀者。
Thumbnail
介紹朋友新開的蝦皮選物店『10樓2選物店』,並分享方格子與蝦皮合作的分潤計畫,註冊流程簡單,0成本、無綁約,推薦給想增加收入的讀者。
Thumbnail
LeetCode 是一個程式語言版的線上題庫平臺,提供題目描述、程式碼區塊、解題者分享的解法和疑問討論。藉由這篇文章分享我在 LeetCode 上的使用經驗和觀點,包括刷題的重要性、解題心態和練習目標。
Thumbnail
LeetCode 是一個程式語言版的線上題庫平臺,提供題目描述、程式碼區塊、解題者分享的解法和疑問討論。藉由這篇文章分享我在 LeetCode 上的使用經驗和觀點,包括刷題的重要性、解題心態和練習目標。
Thumbnail
題目敘述 題目給定一個鏈結串列中的節點Node,要求我們從鏈結串列中刪除該節點。 題目保證該節點不是tail node。 題目要求我們in-place原位操作。 原本的英文題目敘述 測試範例 Example 1: Input: head = [4,5,1,9], node = 5
Thumbnail
題目敘述 題目給定一個鏈結串列中的節點Node,要求我們從鏈結串列中刪除該節點。 題目保證該節點不是tail node。 題目要求我們in-place原位操作。 原本的英文題目敘述 測試範例 Example 1: Input: head = [4,5,1,9], node = 5
Thumbnail
題目敘述 題目會給我們一個定義好的類別和function介面,要求我們實作建構子和ping() function來滿足指定的需求。 RecentCounter類別的建構子 建構子應該初始化來電紀錄,內容為空(零筆資料) int ping(int t) t代表來電時刻,單位是毫秒m
Thumbnail
題目敘述 題目會給我們一個定義好的類別和function介面,要求我們實作建構子和ping() function來滿足指定的需求。 RecentCounter類別的建構子 建構子應該初始化來電紀錄,內容為空(零筆資料) int ping(int t) t代表來電時刻,單位是毫秒m
Thumbnail
題目敘述 題目會給我們一個字串s作為輸入,要求我們以white space空白為切割符號,切割出每個單字,並且反轉其順序後,以字串形式最為最後的輸出。 題目的原文敘述 測試範例 Example 1: Input: s = "the sky is blue" Output: "blue i
Thumbnail
題目敘述 題目會給我們一個字串s作為輸入,要求我們以white space空白為切割符號,切割出每個單字,並且反轉其順序後,以字串形式最為最後的輸出。 題目的原文敘述 測試範例 Example 1: Input: s = "the sky is blue" Output: "blue i
Thumbnail
題目敘述 題目會給我們兩個輸入,字串s和字串t,要求我們判定s是否為t的子序列(Subsequence)? 題目的原文敘述 測試範例 Example 1: Input: s = "abc", t = "ahbgdc" Output: true Example 2: Input:
Thumbnail
題目敘述 題目會給我們兩個輸入,字串s和字串t,要求我們判定s是否為t的子序列(Subsequence)? 題目的原文敘述 測試範例 Example 1: Input: s = "abc", t = "ahbgdc" Output: true Example 2: Input:
Thumbnail
題目敘述 題目會給定兩個輸入。 第一個輸入是關鍵字清單products,第二個是使用者輸入的字串searchWord。 要求我們實現關鍵字搜尋建議系統,使用者每輸入一個字元就推薦一次。 推薦時,優先返回字典序(Lecial order)最接近的關鍵字,最多不要超過三個關鍵字。 題目的原文
Thumbnail
題目敘述 題目會給定兩個輸入。 第一個輸入是關鍵字清單products,第二個是使用者輸入的字串searchWord。 要求我們實現關鍵字搜尋建議系統,使用者每輸入一個字元就推薦一次。 推薦時,優先返回字典序(Lecial order)最接近的關鍵字,最多不要超過三個關鍵字。 題目的原文
Thumbnail
情境描述 小明身為Linux系統工程師, 目前接到一個緊急任務, 需要在客戶端確保csv表的某個欄位的值不能重複, 對於軟體工程師來說只要寫個程式就能夠解決, 但客戶端並沒有相關的程式語言啊! 這時候只能夠使用現成的工具來完成,而經驗老道的我們很快就想到了解決方法, 不要急, 就讓我們一步
Thumbnail
情境描述 小明身為Linux系統工程師, 目前接到一個緊急任務, 需要在客戶端確保csv表的某個欄位的值不能重複, 對於軟體工程師來說只要寫個程式就能夠解決, 但客戶端並沒有相關的程式語言啊! 這時候只能夠使用現成的工具來完成,而經驗老道的我們很快就想到了解決方法, 不要急, 就讓我們一步
Thumbnail
題目會給定兩個字串s,t,把裡面的井字號#視為鍵盤上的backspace,往前(往左方)吃掉最靠近的字元。 請位最後全部依照規則處理完以後,s,t剩下的字串內容兩者是否相等?
Thumbnail
題目會給定兩個字串s,t,把裡面的井字號#視為鍵盤上的backspace,往前(往左方)吃掉最靠近的字元。 請位最後全部依照規則處理完以後,s,t剩下的字串內容兩者是否相等?
Thumbnail
圖片來源... 故事的起源… 圖片來源... 首先我們來查查看目標的目錄有多少檔案, 結果卻… # 查看檔案有多少量 ll *.txt|wc -l # 悲劇發生了... -bash: /usr/bin/ls: Argument list too long 那我們試著搬移檔案呢?
Thumbnail
圖片來源... 故事的起源… 圖片來源... 首先我們來查查看目標的目錄有多少檔案, 結果卻… # 查看檔案有多少量 ll *.txt|wc -l # 悲劇發生了... -bash: /usr/bin/ls: Argument list too long 那我們試著搬移檔案呢?
追蹤感興趣的內容從 Google News 追蹤更多 vocus 的最新精選內容追蹤 Google News