Signal9Signal9 — home
online
back to labs

Functions: a Reusable Logger

MediumShell Scripting10-20 min
The brief

Functions package reusable logic. Write a log() function that timestamps each message, then use it.

Write your script at /root/scripts/logger.sh. It must define a function log() which appends 'TIMESTAMP message' to /root/out/app.log, and calls it exactly three times with these messages, in order:

starting up

doing work

shutting down

Each line must begin with a timestamp (use $(date '+%F %T') or date +%s) followed by the message. Then run the script. Grading checks both halves: your script defines log(), and app.log holds three real-timestamped lines carrying those three messages in order.

What you'll do
  • Write /root/scripts/logger.sh defining a log() function that prepends a timestamp and appends to /root/out/app.log
  • Call it three times: 'starting up', 'doing work', 'shutting down'; then run the script

Hands-on lab: you work on a real Linux box in your browser, graded on the machine's actual state.