ခဏလေး ဒီလိုပဲ စဉ်းစားကြည့်
ဒီ lesson က tutorial ရဲ့ Intermediate/Advanced chapter တွေမှာ သင်ခဲ့တဲ့ shell script, process management, cron, disk, ssh/scp/rsync, systemd, log troubleshooting skill တွေကို တစ်ခုတည်း သီးခြားမဟုတ်ဘဲ ပေါင်းစပ်ပြီး သုံးစေတဲ့ scenario-based task တွေပါ။ Real server operator တစ်ယောက် နေ့စဉ်ကြုံရတဲ့ 'process မ run ဘူး', 'disk space ကုန်နေတယ်', 'remote server ကို file ပို့ရမယ်' စတဲ့ ပြဿနာမျိုးတွေကို simulate လုပ်ကြည့်တာပါ။ Task 1 ကနေ 4 ဆီကို difficulty တဆင့်ချင်း မြင့်တက်သွားပါတယ် — နောက်ဆုံး task က troubleshooting mindset ကိုပါ စမ်းစစ်ပါလိမ့်မယ်။ Command တစ်ခုချင်းစီ run ပြီးတိုင်း output ကို သေချာဖတ်ပြီးမှ နောက် step ဆက်ပါ။
လေ့ကျင့်ခန်းများ
Task 1: process တစ်ခု (ဥပမာ sleep 500 &) ကို background မှာ run ထားပြီး, ဒီ process name ကို ps aux | grep နဲ့ ရှာကာ run နေရင် echo "Running" မဟုတ်ရင် echo "Not running" ထုတ်ပေးတဲ့ check-process.sh script ကို ရေးပါ။ Task 2: အထက်က script ကို crontab -e နဲ့ 5 မိနစ်တစ်ခါ run အောင် schedule လုပ်ပြီး, result ကို ~/check.log ထဲ append (>>) ဖြစ်အောင် ချိတ်ပါ။ Task 3: /var/log (ဒါမှမဟုတ် permission ရတဲ့ log directory) အောက်က file တွေကို du -ah | sort -rh | head -5 နဲ့ size အကြီးဆုံး 5 ခု ရှာပြီး, 7 ရက်ထက်ကြီးတဲ့ log file တွေကို tar -czf ဖြင့် archive ပြီး ဖျက်ပါ (find ... -mtime +7 ကို tar/rm နဲ့ ပေါင်းသုံးပါ)။ Task 4: local test user account တစ်ခု (သို့) home VM/VPS တစ်ခုကို ssh-keygen + ssh-copy-id နဲ့ passwordless SSH setup လုပ်ပြီး, rsync -avz ကို သုံးကာ folder တစ်ခုလုံး remote ကို sync လုပ်ကြည့်ပါ — sync ပြီးရင် ssh remote-host "md5sum file" နဲ့ local checksum ကို ယှဉ်စစ်ပါ။
Code နမူနာ
#!/bin/bash
# check-process.sh — Task 1 & 2
PROCESS_NAME="sleep"
if ps aux | grep -v grep | grep -q "$PROCESS_NAME"; then
echo "$(date): $PROCESS_NAME is Running" >> ~/check.log
else
echo "$(date): $PROCESS_NAME is NOT running" >> ~/check.log
fi
# crontab -e ထဲမှာ ဒီလို ထည့်ပါ (5 မိနစ်တစ်ခါ):
# */5 * * * * /bin/bash ~/check-process.sh
# Task 3: largest files + old log archive
du -ah /var/log 2>/dev/null | sort -rh | head -5
find /var/log -type f -mtime +7 -print0 | tar -czvf old-logs.tar.gz --null -T -
find /var/log -type f -mtime +7 -delete
# Task 4: passwordless SSH + rsync sync
ssh-keygen -t ed25519 -f ~/.ssh/practice_key -N ""
ssh-copy-id -i ~/.ssh/practice_key.pub user@remote-host
rsync -avz -e "ssh -i ~/.ssh/practice_key" ~/practice-lab/ user@remote-host:~/practice-lab-copy/check.log ထဲမှာ timestamp တွဲပြီး process status log ဝင်နေမှာဖြစ်ပြီး, old-logs.tar.gz ထဲမှာ 7 ရက်ထက်ကြီးတဲ့ log ဖိုင်တွေ archive ဖြစ်နေကာ, remote-host ပေါ်မှာ practice-lab-copy folder ပြည့်စုံစွာ sync ဖြစ်နေပါလိမ့်မယ်။၅ မိနစ် စမ်းကြည့်
5 မိနစ်အတွင်း check-process.sh ကို process name PROCESS_NAME="nonexistent123" လို့ ပြောင်းပြီး run ကြည့်ကာ, log file ထဲမှာ Not running status မှန်ကန်စွာ ရေးမိလားဆိုတာ tail -f ~/check.log နဲ့ live monitor လုပ်ကြည့်ပါ။
သတိလေးတစ်ချက်
find ... -delete နဲ့ tar archive command တွေကို production log directory ပေါ်မှာ တိုက်ရိုက်စမ်းမသုံးပါနဲ့ — test folder တစ်ခု ဖန်တီးပြီးမှ practice လုပ်ပါ, real /var/log ဆွဲပြင်ရင် system log history ပျောက်သွားနိုင်ပါတယ်။