A script must process a 50 GB log file line by line quickly. What tools would you use?
IntermediateScenarioScheduling, automation and scripting
Answer
Situation read → Avoid bash loops for big data; use stream tools.
What I'd do →
LC_ALL=C grep -F ' 500 ' access.log | awk '{print $7}' | sort | uniq -c | sort -rn | head
# split into chunks and process in parallel
split -n l/8 access.log part_ && ls part_* | parallel -j8 "grep -c ERROR {}"
Why → while read in bash is very slow on large files; grep, awk, sort are optimised C. LC_ALL=C skips locale processing for big speedups.
Interview tip → Mention zgrep/zcat for compressed logs instead of unpacking.
More on Scheduling, automation and scripting
A database dump must run every night at 1:30 AM. How do you schedule it with cron so it is reliable?BeginnerConvert that nightly cron job to a systemd timer. Why would you?IntermediateA cron job runs every 5 minutes, but sometimes takes 8 minutes and two copies overlap, corrupting data. How do you prevent that?BeginnerYou have 300 servers running the same cron job at midnight, and they hammer a shared API. How do you fix it?IntermediateA job must run on the last day of every month. Cron has no "last day" field. What do you do?IntermediateYou inherited a server and need to know every scheduled job on it. Where do you look?Beginner