Rotate and Compress Device Logs

Easy Shell OS Asked at Cisco
Solve this problem

Write a log rotation script for an embedded device with limited flash: keep a bounded number of compressed archives and never let the log directory exceed a size cap.

Constraints

  • Keep at most 5 rotated archives.
  • Compress rotated files with gzip.
  • Delete oldest archives first if the directory exceeds the size cap.
  • Must not lose the active log file.
  • Safe to run twice in a row.
  • Exit 0 on success.
Starter codeShell
1#!/bin/sh2# TODO: rotate, compress, prune