trap_cleanup.sh

ShellMaster

Explorer

C40
C++40
C#40
Dart40
Go40
Java40
JavaScript40
Kotlin40
Objective-C40
Perl40
PHP40
Python40
R40
Ruby40
Rust40
Shell
Beginner10
Intermediate10
Advanced10
Expert5
Master5
parallel_batch.sh
trap_cleanup.sh
json_parser.sh
config_loader.sh
retry_wrapper.sh
Swift40
TypeScript40
trap_cleanup.sh
Click to focus
1
2
3
4
5
6
7
8
9
10
11
12
13
#!/bin/bash
set -euo pipefail
readonly LOCKFILE="/var/run/${0##*/}.lock"
readonly TMPDIR="$(mktemp -d)"
cleanup() {
   local exit_code=$?
   rm -rf "$TMPDIR"
   [[ -f "$LOCKFILE" ]] && rm -f "$LOCKFILE"
   exit $exit_code
}
trap cleanup EXIT INT TERM
exec 200>"$LOCKFILE"
flock -n 200 || { echo "Already running"; exit 1; }
0WPM0%0:000/323(0%)|Ln 1, Col 1
UTF-8Shell

Related Exercises