-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathSHELL-MKTEMP-FILE.txt
More file actions
33 lines (21 loc) · 892 Bytes
/
SHELL-MKTEMP-FILE.txt
File metadata and controls
33 lines (21 loc) · 892 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
https://www.shellscript.sh/tips/mktemp/
https://renenyffenegger.ch/notes/Linux/shell/commands/mktemp
https://www.putorius.net/working-with-temporary-files.html
https://code-maven.com/create-temporary-directory-on-linux-using-bash
#!/bin/bash
trap 'rm -f "$TMPFILE"' EXIT
TMPFILE=$(mktemp)|| exit 1
echo "Our temp file is $TMPFILE"
## Create a log file
logfile=$(mktemp)
## Run your command and have it print into the log file
## when it's finsihed.
command1 && echo 1 > $logfile &
## Wait for it. The [ ! -s $logfile ] is true while the file is
## empty. The -s means "check that the file is NOT empty" so ! -s
## means the opposite, check that the file IS empty. So, since
## the command above will print into the file as soon as it's finished
## this loop will run as long as the previous command si runnning.
while [ ! -s $logfile ]; do sleep 1; done
## continue
command2