Skip to content

Commit 3e3a59e

Browse files
shellcheck linter: use bash extras/devel-tools/strace-brick.sh
This commit changes the shell to #!/usr/bin/env bash. This series aim to reduce the shellcheck logs. Signed-off-by: Thales Antunes de Oliveira Barretto <[email protected]>
1 parent b96889f commit 3e3a59e

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

extras/devel-tools/strace-brick.sh

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
brick_process_name=$1
66
min_watch_cpu=$2
7-
if [ ! $brick_process_name ]; then
7+
if [ -z "$brick_process_name" ]; then
88
brick_process_name=glusterfsd
99
fi
1010

11-
if [ ! $min_watch_cpu ]; then
11+
if [ -z "$min_watch_cpu" ]; then
1212
min_watch_cpu=50
1313
fi
1414

@@ -18,13 +18,13 @@ break=false
1818

1919
while ! $break;
2020
do
21-
mypids=( $(pgrep $brick_process_name) )
21+
mapfile -t mypids < <(pgrep "$brick_process_name")
2222
echo "mypids: ${mypids[*]}"
2323

24-
pid_args=$(echo ${mypids[*]} | sed -e 's/ / -p /g;s/^/-p /')
24+
pid_args=$(echo "${mypids[*]}" | sed -e 's/ / -p /g;s/^/-p /')
2525
echo "pid_args: $pid_args"
2626

27-
pcpu=( $(ps $pid_args -o pcpu -h ) )
27+
mapfile -t pcpu < <(ps "$pid_args" -o pcpu -h )
2828
echo "pcpu: ${pcpu[*]}"
2929

3030
wait_longer=false
@@ -34,16 +34,19 @@ do
3434
echo "i: $i"
3535
echo "mypids[$i]: ${mypids[$i]}"
3636

37-
int_pcpu=$(echo ${pcpu[$i]} | cut -f 1 -d '.')
37+
int_pcpu="$(echo "${pcpu[$i]}" | cut -f 1 -d '.')"
3838
echo "int_pcpu: $int_pcpu"
39-
if [ ! $int_pcpu ] || [ ! $min_watch_cpu ]; then
39+
if [ -z "$int_pcpu" ] || [ -z "$min_watch_cpu" ]; then
4040
break=true
4141
echo "breaking"
4242
fi
43-
if [ $int_pcpu -ge $min_watch_cpu ]; then
43+
if [ "$int_pcpu" -ge "$min_watch_cpu" ]; then
4444
wait_longer=true
4545
mydirname="${brick_process_name}-${mypids[$i]}-$(date --utc +'%Y%m%d-%H%M%S.%N')"
46-
$(mkdir $mydirname && cd $mydirname && timeout --kill-after=5 --signal=KILL 60 nice -n -19 strace -p ${mypids[$i]} -ff -tt -T -o $brick_process_name) &
46+
$(mkdir "$mydirname" \
47+
&& cd "$mydirname" \
48+
&& timeout --kill-after=5 --signal=KILL 60 nice -n -19 \
49+
strace -p "${mypids[$i]}" -ff -tt -T -o "$brick_process_name") &
4750
fi
4851
done
4952

0 commit comments

Comments
 (0)