Never Run Twice at Once

medium 20 XP ~7 minHands-on lab Pro

/home/student/bin/sync.sh runs from cron every minute, but on slow days a run takes longer than a minute and two copies overwrite each other's data.

Task

Change sync.sh so that only one copy can run at a time:

  • while one copy is running, a second one prints sync: already running to stderr and exits 1 straight away, without doing any work
  • the first copy carries on normally
  • once a copy has finished, the next run works again
  • if a copy is killed with kill -9, the next run must still work (no stale lock blocks it)

About this machine

Ubuntu 24.04 with no internet access. You are student with passwordless sudo. The grader checks the final state of the machine, not the commands you typed. Values like names and ports are generated for you.

TerminalNot started

Your machine is ready to start

Create a free account to open a machine and get graded.